<p>This sort of thing is perfectly valid and valuable, provided that students already understand the underlying structure. So if they understand your first loop without continue (but with the print in place) the adding <code>continue</code> lets them see the effect dramatically. </p>

<p>The same is true of your second example. If they understand strings as arrays or lists (or ... whatever term is appropriate in your language) then introducing the [] "box" operator as selection makes sense. </p>

<p>But I wouldn't write a large program as an exemplar of good programming if it had these kinds of things. </p>

<p>But note also, that throwing in a continue in a loop is sometimes good for debugging, so it isn't entirely useless as a technique in "real" programming. </p>

<h3>tl;dr teaching by showing modifications to a known base is fine.</h3>

<hr>

<p>By the way. In some languages asking students to decipher obfuscated code can be a useful exercise to make sure they know the basic rules. Asking them to clean it up is even better.   </p>

CC BY-SA 3.0
2017-10-04T19:37:10.167Z
Question says 'introduce', so I think you're saying 'no, but later'?
Sean Houlihane
CC BY-SA 3.0
2017-10-04T19:38:33.263Z
Actually no, I'm saying "yes", introduce is fine. Introduce "continue" into a known base. That was the point, actually.
Buffy
CC BY-SA 3.0
2017-10-04T19:33:43.863Z
2017-10-04T19:33:43.863Z
Buffy
<p>I found the following example in chapter two of <a href="https://github.com/mdipierro/nlib" rel="noreferrer">Annotated Algorithms in Python</a> (<a href="https://raw.githubusercontent.com/mdipierro/nlib/master/docs/book_numerical.pdf" rel="noreferrer">PDF</a>)</p>

<pre><code>&gt;&gt;&gt; for i in [1, 2, 3]:
... print i
... continue
... print 'test'
1
2
3
</code></pre>

<p>This does demonstrate what <code>continue</code> does, but you would never write something like this in real code. You would just leave out <code>continue</code> and <code>print "test"</code> entirely. It seems like this example might be counter-productive.</p>

<p>Another type of example that I have seen elsewhere that I think might be counter-productive is indexing into string literals. For example, in some languages you can write the following:</p>

<pre><code>"Hello World!"[0]
</code></pre>

<p>which would evaluate to <code>"H"</code> but if you actually wanted an expression that evaluated to <code>"H"</code>, you would just use <code>"H"</code>!</p>

<p>Does it make sense to use contrived examples like this, or is it likely to introduce confusion in students?</p>

<introductory-lesson>
Is it bad to introduce language features in ways that are different than they will be used in practice?
# Is it bad to introduce language features in ways that are different than they will be used in practice?

(Asked by: username_0 on 2017-10-04)

I found the following example in chapter two of Annotated Algorithms in Python (PDF)
>>> for i in [1, 2, 3]:
... print i
... continue
... print 'test'
1
2
3

This does demonstrate what continue does, but you would never write something like this in real code. You would just leave out continue and print "test" entirely. It seems like this example might be counter-productive.
Another type of example that I have seen elsewhere that I think might be counter-productive is indexing into string literals. For example, in some languages you can write the following:
"Hello World!"[0]

which would evaluate to "H" but if you actually wanted an expression that evaluated to "H", you would just use "H"!
Does it make sense to use contrived examples like this, or is it likely to introduce confusion in students?

**Tags:** introductory-lesson


---

## 1 answers

### Answer by username_1 on 2017-10-04. Score: 7 | Accepted answer

This sort of thing is perfectly valid and valuable, provided that students already understand the underlying structure. So if they understand your first loop without continue (but with the print in place) the adding `continue` lets them see the effect dramatically.

The same is true of your second example. If they understand strings as arrays or lists (or ... whatever term is appropriate in your language) then introducing the [] "box" operator as selection makes sense.

But I wouldn't write a large program as an exemplar of good programming if it had these kinds of things.

But note also, that throwing in a continue in a loop is sometimes good for debugging, so it isn't entirely useless as a technique in "real" programming.

### tl;dr teaching by showing modifications to a known base is fine.

---

By the way. In some languages asking students to decipher obfuscated code can be a useful exercise to make sure they know the basic rules. Asking them to clean it up is even better.

> **Comments:**
> **username_2**: Question says 'introduce', so I think you're saying 'no, but later'?  
> **username_1**: Actually no, I'm saying "yes", introduce is fine. Introduce "continue" into a known base. That was the point, actually.  

---

