[Python-ideas] for-while statement

Chris Angelico rosuav at gmail.com
Wed Feb 19 15:05:23 CET 2014


On Thu, Feb 20, 2014 at 12:34 AM, Alejandro López Correa <alc at spika.net> wrote:
> I think adding an optional "WHILE" clause in "FOR" loops might be
> useful sometimes (shorter code and/or improved readability):
>
> for #VAR# in #SEQUENCE# while #WATCHDOG_EXPRESSION#:
>   #CODE_BLOCK#

Suggestion: Look at REXX's loops for some ideas and use-cases.

http://www.kilowattsoftware.com/tutorial/rexx/do.htm

REXX lets you combine zero or more loop conditions, including "WHILE
condition", "FOR iteration_count", and so on. You may also want to
consider a filtered iteration, with "IF condition" (which would be
like putting "if not condition: continue" at the top of the loop).

There are definite use-cases for all of these. The question is, which
ones are worth blessing with syntax?

ChrisA


More information about the Python-ideas mailing list