On 2017-10-04, Stefan Ram <r...@zedat.fu-berlin.de> wrote: > r...@zedat.fu-berlin.de (Stefan Ram) writes: >>Maybe this way: Use a while-loop and try-catch to get values >>from an iterator until exhausted, and then introduce the >>for-loop as an abbreviation for that. > > # while-loop > > iterable = range( 3 ) > > iterator = iter( iterable ) > try: > while True: > i = next( iterator ) > print( i ) > except StopIteration: > pass > > iterator = iter( iterable ) > try: > while True: > i = next( iterator ) > print( i ) > except StopIteration: > pass > > # for-loop as-an-abbreviation > > iterable = range( 3 ) > > for i in iterable: > print( i ) > > for i in iterable: > print( i )
That looks the opposite of an excellent way to teach iterators. If you insist they understand the iterator protocol and exception handling first they're bound to think iteration is a hovercraft full of eels. -- Neil Cerutti -- https://mail.python.org/mailman/listinfo/python-list