Is this PEP-able? fwhile

J

jimjhb

Syntax:
fwhile X in ListY and conditionZ:

There is precedent in Algol 68:

for i from 0 to n while safe(i) do .. od

which would also make a python proposal that needs no new key words:

for i in range(n) while safe(i): ..

The benefit of the syntax would be to concentrate the code
expressing the domain of the loop rather than have it in separate locations..

Not a big win in my opinion.

Neil

Neil,

I disagree. The problem IMO is that python 'for's are a different kind of 'for' in that they have no explicit indexing and no explicit range test; just a list which has elements drawn from it. This is amazingly
powerful and concise. Unfortunately, the "breaks are just gotos" communityoften ruins this conciseness by going to 'while' or itertools (or worse) to avoid adding a break to a 'for' which needs to be terminated early.

I think suggestions like yours and Fabio's are good ones. If 'for' has an 'else', why not a 'while'?

FWIW, I can sympathize with the 'no breaks or continues' notion, at least largely so. That said, I have used gotos sparingly in C. The problem is that applying the no-breaks notion to the python 'for' is problematic becauseas I said earlier, the python 'for' is a special kind of 'for'. Maybe Guido needs to be seen in public hugging a break statement..... :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,757
Messages
2,569,543
Members
45,026
Latest member
camilin05

Latest Threads

Top