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?