for / while else doesn't make sense
Lawrence D’Oliveiro
lawrencedo99 at gmail.com
Mon Jun 6 20:51:24 EDT 2016
On Sunday, June 5, 2016 at 11:43:20 PM UTC+12, Marko Rauhamaa wrote:
> I often experiment with different loop constructs to find the one most
> pleasing to the eye. Working directly off iterators is quite rare but a
> while-vs-for consideration is frequent. Also, should the stepping part
> be in the beginning, middle or end of the loop body?
It is nice to have a common, versatile looping form which can be arranged in different ways to suit the problem at hand. That’s why I like the C-style for-statement.
Here’s another example <https://github.com/ldo/ipy_magics/blob/master/rman_magic.py>, for the consideration of those who don’t seem too familiar with looping:
while True :
while True :
line = next(input_line, None)
if line != None :
if len(include_stack) == 0 :
linenr += 1
#end if
break
#end if
if len(include_stack) == 0 :
break
input_line = include_stack.pop()
#end while
if line == None or ... line contains something special ... :
...
if line == None :
break
... process special line ...
... replace with None to indicate it’s been processed ...
#end if
if line != None :
... process regular line ...
#end if
#end while
More information about the Python-list
mailing list