Re: [Python-ideas] "while:" for the loop
On 02/10/18 12:31, Jonathan Fine wrote: Mikhail V has suggested "while:" as a shorthand for "while True:". He's also provided a helpful list of URLs for related discussion. I'd like to suggest another approach. Before we hare off into the middle distance, could you show that there is a problem that needs to be addressed here? I killfiled Mikhail a long time ago, so I haven't actually seen any justification here beyond "I don't want to have to type five more characters." My suggestion is to improved documentation and help. For me a search for python "while True" produces as the top result https://wiki.python.org/moin/WhileLoop. Please take a look at this page. I don't think it's suitable for novices. In particular, about 25% of the page compares "while 1:" to "while True:" and changes between Python2 and Python3. Is it intended solely for novices? Searching for site:docs.python.org "while True" produces as top result https://docs.python.org/3/tutorial/controlflow.html. Please also look at this page. It has two examples of "while True:", but does not say that "while True:" means loop forever (unless there is a break or an exception). This is an invidious example. "while" is actually introduced on the previous page, as the first paragraph says. Expecting a statement of the blindingly obvious here is inappropriate, surely. (And yes, my experience with early teens is that it *is* blindingly obvious.) Today I saw https://blog.codeclub.org.uk/2018/06/13/how-to-move-from-scratch-to-python-in-code-club/ On this page, a Code Club volunteer gives as debugging advice I use comparisons of Scratch to Python at the beginning, for example to explain that ‘while True’ is the same as the ‘Forever’ block. I also have some Python cheat sheets which give examples of common Python code. Some of the learners find it easier to debug Python than Scratch, because Python gives you error messages to indicate what went wrong. It’s usually down to spelling errors! Um, yay? I'm not sure what your point here is. So Scratch has a Forever block, so what? My final URL is https://www.youtube.com/watch?v=QEJ8tE9lAeE. This is a 3 minute video: Python For Beginners - How to use a While True Loop in Python. Something that can be done now, which can soon bring benefit to many, is to find or write material that will help novices master Python idioms such as "while True:". I'm sure the Code Club would like to put such material on its web site. I'm sorry, but I find the idea that idioms like "while True:" need to be *mastered* a tad patronising. I have genuinely not had to take more than five minutes to get it through to an uninterested and not particularly technical 12-year old. -- Rhodri James *-* Kynesim Ltd ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Re: [Python-ideas] "while:" for the loop
Mikhail V has suggested "while:" as a shorthand for "while True:". He's also provided a helpful list of URLs for related discussion. I'd like to suggest another approach. My suggestion is to improved documentation and help. For me a search for python "while True" produces as the top result https://wiki.python.org/moin/WhileLoop. Please take a look at this page. I don't think it's suitable for novices. In particular, about 25% of the page compares "while 1:" to "while True:" and changes between Python2 and Python3. Searching for site:docs.python.org "while True" produces as top result https://docs.python.org/3/tutorial/controlflow.html. Please also look at this page. It has two examples of "while True:", but does not say that "while True:" means loop forever (unless there is a break or an exception). Today I saw https://blog.codeclub.org.uk/2018/06/13/how-to-move-from-scratch-to-python-in-code-club/ On this page, a Code Club volunteer gives as debugging advice I use comparisons of Scratch to Python at the beginning, for example to explain that ‘while True’ is the same as the ‘Forever’ block. I also have some Python cheat sheets which give examples of common Python code. Some of the learners find it easier to debug Python than Scratch, because Python gives you error messages to indicate what went wrong. It’s usually down to spelling errors! My final URL is https://www.youtube.com/watch?v=QEJ8tE9lAeE. This is a 3 minute video: Python For Beginners - How to use a While True Loop in Python. Something that can be done now, which can soon bring benefit to many, is to find or write material that will help novices master Python idioms such as "while True:". I'm sure the Code Club would like to put such material on its web site. -- Jonathan On Sat, Sep 29, 2018 at 4:58 AM Mikhail V wrote: > > I put the list of related discussion here, just in case. > > Same suggestion: > https://mail.python.org/pipermail/python-dev/2005-July/054914.html > > Idea for the "loop" keyword: > https://mail.python.org/pipermail/python-ideas/2014-June/028202.html > (followed by the same suggestion from @Random832: > https://mail.python.org/pipermail/python-ideas/2014-June/028220.html) > > Somewhat related PEP (rejected) + discussion links inside: > https://legacy.python.org/dev/peps/pep-0315/ > (I've meditated a bit on this - but could not get what was > actually the point of that idea.) > > Plus some other related discussions, maybe not directly related, > but something along the lines might be interesting. > > An old and lively one: > https://mail.python.org/pipermail/python-list/1999-April/002557.html > https://mail.python.org/pipermail/python-list/1999-May/008535.html > Another one: > https://mail.python.org/pipermail/python-list/2000-December/029972.html > ( Particularly this: > https://mail.python.org/pipermail/python-list/2000-December/052694.html > ) > Yet another "1" vs "True" debate: > https://mail.python.org/pipermail/python-list/2012-January/618649.html > New era: > https://mail.python.org/pipermail/python-list/2017-April/721182.html > ___ > Python-ideas mailing list > Python-ideas@python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Re: [Python-ideas] "while:" for the loop
I put the list of related discussion here, just in case. Same suggestion: https://mail.python.org/pipermail/python-dev/2005-July/054914.html Idea for the "loop" keyword: https://mail.python.org/pipermail/python-ideas/2014-June/028202.html (followed by the same suggestion from @Random832: https://mail.python.org/pipermail/python-ideas/2014-June/028220.html) Somewhat related PEP (rejected) + discussion links inside: https://legacy.python.org/dev/peps/pep-0315/ (I've meditated a bit on this - but could not get what was actually the point of that idea.) Plus some other related discussions, maybe not directly related, but something along the lines might be interesting. An old and lively one: https://mail.python.org/pipermail/python-list/1999-April/002557.html https://mail.python.org/pipermail/python-list/1999-May/008535.html Another one: https://mail.python.org/pipermail/python-list/2000-December/029972.html ( Particularly this: https://mail.python.org/pipermail/python-list/2000-December/052694.html ) Yet another "1" vs "True" debate: https://mail.python.org/pipermail/python-list/2012-January/618649.html New era: https://mail.python.org/pipermail/python-list/2017-April/721182.html ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Re: [Python-ideas] "while:" for the loop
On 26/09/18 18:23, Michael Selik wrote: Guido has repeatedly (haha) rejected this proposal [0]. He has written that he considered it, but decided that in practical code one almost always loops over data, and does not want an arbitrary number of iterations. The range object solves this problem. Years ago, I proposed a do...loop. Guido rejected that. As an aside, here's a pattern you can use for do...loops. def do_loop(): if True: return True return False while do_loop(): pass Cheers, Hans ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Re: [Python-ideas] "while:" for the loop
Mikhail V writes: > In the first linked discussion, e.g. Mr. D'Aprano and Mr. Coghlan (from my > impression both from dev team) unambiguosly claimed that adding e.g. > "loop" as a loop token lead to necessity of excluding ALL > variables and functions/methods named "loop" from all sources. > https://mail.python.org/pipermail/python-ideas/2014-June/028206.html AIUI, the situation is this: (Executive summary) The restriction was imposed by Guido as a design feature. (Excruciating detail) There are three general possibilities: 1. The syntax recognizes some tokens as significant, but they are not reserved at all. It's arguable that Lisp works this way (some will argue that only parentheses create syntax in Lisp, but I don't think humans perceive it that way). 2. The syntax recognizes keywords (ie, reserved for their syntactic meaning) in a context-dependent fashion. In Python, an example might be treating break and continue this way: inside a loop they are reserved, but you can use them as identifiers outside of a loop. I believe that the async-related keywords were treated this way at first. 3. Syntactically-significant keywords are reserved for their syntactic purpose globally. This is the rule in Python. Guido chose #3 as a matter of designing Python. IIRC, the logic was that #1 admits awful unreadable code like "if if then then else else" and nobody needs to write that, and it's hard to write a grammar for it that allows generation of good error messages. The rules for #2, being context-dependent, are unclear to most humans and you don't get a significant benefit for many keywords (consider how useful "break" would be as a variable if you couldn't reference it in a loop!) Besides not having those disadvantages, #3 has the advantage of a simpler grammar and more transparent syntax error reporting, at the minor cost of reserving a very few tokens globally. This does get annoying sometimes (you see a lot of use of 'class_' and 'klass' in some contexts), but I hardly ever notice it. For me at least, shadowing builtins is a much more frequent problem/annoyance. ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Re: [Python-ideas] "while:" for the loop
On 2018-09-25 17:46, Mikhail V wrote: I suggest allowing "while:" syntax for the infinite loop. I.e. instead of "while 1:" and "while True:" notations. I like this idea, and would have use for it. -Mike ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Re: [Python-ideas] "while:" for the loop
On Wed, Sep 26, 2018 at 4:46 PM Mark E. Haase wrote: > > On Tue, Sep 25, 2018 at 8:47 PM Mikhail V wrote: >> >> As for statistics - IIRC someone gave statistics once, but the only >> thing I can remember [...] "while 1/True" is used quite a lot in the > > This proposal would be a lot stronger if you included those statistics > in this thread and showed examples of stdlib code before/after the > proposed syntax change. I can't find the discussion with the statistics, but here two related discussions: https://mail.python.org/pipermail/python-ideas/2014-June/028202.html https://mail.python.org/pipermail/python-ideas/2017-March/045344.html The statistics was in one of 2016 or 2017 discussions, but I have failed to find it. By any chance- maybe someone can do it here? I could do but it would need to exclude comments/ strings from the search - I don't have a such tool at hand. Numbers for "while 1" and "while True" should suffice. > I imagine that a new loop keyword could be introduced in > a backwards-compatible way. Now I don't know whom to believe. In the first linked discussion, e.g. Mr. D'Aprano and Mr. Coghlan (from my impression both from dev team) unambiguosly claimed that adding e.g. "loop" as a loop token lead to necessity of excluding ALL variables and functions/methods named "loop" from all sources. https://mail.python.org/pipermail/python-ideas/2014-June/028206.html So what is the real situation? What I can tell - simple syntax highlighting systems and syntax checkers will not be able to tell the difference between the statement initial token and identifier. Speaking of a new keyword: I can see only one benefit of new keyword in this case: it can be extended with additional usage for "loop N" loop N: print ("=") # iterates N times And I like the word "loop" slightly more than "repeat". But still - even if it's technically possible without breaking something, I am a bit skeptical, as it's a step towards *bloat*. Keeping less keywords, especially for loops is much more important than 'natural language' semantics. BTW: Here is statistics for the C language: https://stackoverflow.com/questions/20186809/endless-loop-in-c-c It turns out that "for(;;)" is more frequent than "while 1" and "while true". Since Python has "for" than maybe it is possible to use "for" for the infinite loop: for: ... And maybe even it could be made into "for N:"? Now: for N: is SyntaxError, so it might be possible to use "for" for both cases. What do you think? > The meaning of "while" in natural language suggests a period of time or > condition. It does not mean "forever". Therefore, it's not a good semantic > fit. I am not much into the "what it means in natural languages" games, as long as it's understandable and already established token. "while True:" is the infinite loop and the "True" or "1" does not add anything practically useful for working with sources, period. Mostly causes unwanted attention, as I expect expression or variable there. So basically it's noise. "while:" on the contrary is visually clean, gives 100% difference with "while Variable:" - it just tells : here is the start of the loop. So the semantics would be: "while:" is an infinite loop, that's it. Mikhail ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Re: [Python-ideas] "while:" for the loop
On Wed, Sep 26, 2018, 19:30 David Mertz wrote: > We also have: > > from itertools import count > for i in count(): > ... > > If you want to keep track of how close to infinity you are. :-) > We also have: from itertools import repeat for i in repeat(...): ... with kind regards, -gdg ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Re: [Python-ideas] "while:" for the loop
We also have: from itertools import count for i in count(): ... If you want to keep track of how close to infinity you are. :-) On Wed, Sep 26, 2018, 12:24 PM Michael Selik wrote: > On Wed, Sep 26, 2018, 9:42 AM Tobias Kohn wrote: > >> Although I doubt it will really make it into Python's grammar, I am all >> +1 for the idea of having "repeat" as a loop keyword in Python. >> Actually, I have been using "repeat" as a keyword in Python for quite some >> time now, and found it not only convenient, but also a great help in >> education. >> > Guido has repeatedly (haha) rejected this proposal [0]. He has written > that he considered it, but decided that in practical code one almost always > loops over data, and does not want an arbitrary number of iterations. The > range object solves this problem. > > You might notice that a repeat keyword appears in many graphics-focused > child education languages, but not many "serious" languages. > > [0] I remember at least two times, but can't find them with search at the > moment. > >> ___ > Python-ideas mailing list > Python-ideas@python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ > ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Re: [Python-ideas] "while:" for the loop
On Wed, Sep 26, 2018, 9:42 AM Tobias Kohn wrote: > Although I doubt it will really make it into Python's grammar, I am all +1 > for the idea of having "repeat" as a loop keyword in Python. Actually, I > have been using "repeat" as a keyword in Python for quite some time now, > and found it not only convenient, but also a great help in education. > Guido has repeatedly (haha) rejected this proposal [0]. He has written that he considered it, but decided that in practical code one almost always loops over data, and does not want an arbitrary number of iterations. The range object solves this problem. You might notice that a repeat keyword appears in many graphics-focused child education languages, but not many "serious" languages. [0] I remember at least two times, but can't find them with search at the moment. > ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Re: [Python-ideas] "while:" for the loop
On Tue, Sep 25, 2018 at 8:47 PM Mikhail V wrote: > As for statistics - IIRC someone gave statistics once, but the only > thing I can remember - > "while 1/True" is used quite a lot in the std lib, so the numbers > exceeded my expectation > (because I expected that it's used mostly in algorithms). > This proposal would be a lot stronger if you included those statistics in this thread and showed examples of stdlib code before/after the proposed syntax change. The meaning of "while" in natural language suggests a period of time or condition. It does not mean "forever". Therefore, it's not a good semantic fit. Python has shown a willingness to introduce new keywords: "async" and "await" were added in Python 3.5, which was released about 3 years ago. I imagine that a new loop keyword could be introduced in a backwards-compatible way. If you dislike the look of `while True:`, you can almost always hide it inside a generator and use a `for … in …` block with clearer meaning. ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Re: [Python-ideas] "while:" for the loop
Hello, Although I doubt it will really make it into Python's grammar, I am all +1 for the idea of having "repeat" as a loop keyword in Python. Actually, I have been using "repeat" as a keyword in Python for quite some time now, and found it not only convenient, but also a great help in education. My version of "repeat" has two versions. The primary usage is with an expression that evaluates to a number and specifies how many times the loop is to be repeated: ``` repeat : ``` The second version is without the number, and, indeed, stands for an infinite loop. ``` repeat: ``` I must admit, though, that I had hardly ever reason to use the second form. The implementation is currently built on top of Jython, and uses something like a preprocessor to implement the "repeat"-keyword. In order to keep some backward compatibility, the preprocessor does check a few cases to determine how it is used, and does not always treat it as a keyword. Even though it is possible to write a parser that detects if "repeat" is used as the keyword for a loop or anything else, it will make the syntax very brittle. Take, for instance: ``` repeat (3*4) ``` Now, is this supposed to be a function call, or is it a `repeat`-statement with a missing colon at the end? I therefore would strongly advise against having a word act as a keyword sometimes, and sometimes not. Probably a better solution would be to have something like `from __features__ import repeat` at the beginning. My reason for introducing "repeat" into Python in the first place was because of didactical considerations. Even though it might not seem so, variables are indeed a very hard concept in programming, particularly for younger students. And variables get particularly hard when combined with loops, where the value of a variable changes all the time (this requires a lot of abstract thinking to be properly understood). Loops alone, on the other hand, are a relatively easy concept that could be used early one. So, there is this dilemma: how do you teach loops at an early stage without using variables? That's when I added the "repeat"-keyword for loops, and it has worked marvellously so far :). Cheers, Tobias Quoting James Lu : repeat could be only considered a keyword when it’s used as a loop Sent from my iPhone On Sep 26, 2018, at 8:46 AM, Brice Parent wrote: Le 26/09/2018 à 14:33, James Lu a écrit : what about “repeat:”? Sent from my iPhone I'm not sure it was on purpose, but you replied to me only, and not the entire list. I believe the adding of a new keyword to do something that is already straightforward (`while True:`), and that doesn't add any new functionality, won't probably ever be accepted. ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideasCode of Conduct: http://python.org/psf/codeofconduct/ ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Re: [Python-ideas] "while:" for the loop
repeat could be only considered a keyword when it’s used as a loop Sent from my iPhone > On Sep 26, 2018, at 8:46 AM, Brice Parent wrote: > >> Le 26/09/2018 à 14:33, James Lu a écrit : >> what about “repeat:”? >> >> Sent from my iPhone > I'm not sure it was on purpose, but you replied to me only, and not the > entire list. > I believe the adding of a new keyword to do something that is already > straightforward (`while True:`), and that doesn't add any new functionality, > won't probably ever be accepted. ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Re: [Python-ideas] "while:" for the loop
Le 26/09/2018 à 05:36, Chris Angelico a écrit : On Wed, Sep 26, 2018 at 1:29 PM Mikhail V wrote: On Wed, Sep 26, 2018 at 5:38 AM Chris Angelico wrote: I like saying while "something": where the string describes the loop's real condition. For instance, while "moar data": if reading from a socket, or while "not KeyboardInterrupt": if the loop is meant to be halted by SIGINT. ChrisA if doing so, would not it be more practical to write is as an in-line comment then? with new syntax it could be like this: """ while: # not KeyboardInterrupt asd asd asd asd asd asd asd asd asd """ Similar effect, but I would find it better at least because it would be highlighted as a comment and not as a string, + no quotes noise. A comment is not better than an inline condition, no. I *want* it to be highlighted as part of the code, not as a comment. Because it isn't a comment - it's a loop condition. For what it's worth, I'm not a fan of either solutions. In both cases (string or comment), KeyboardInterrupt seems to be the only way to get out of the loop, which which even if it were the case, it would breaks the DRY idea, because if you add in the future a reason to break out of the loop, you'd have to write the condition+break and update the comment/string to still be consistent. I don't think `while True:` is not explicit. If you think about it, True will always evaluate positively (right??), so it can't be the hardest part of learning Python. But in some cases, mostly when I work on tiny microptyhon projects that I share with non-python experts, where I avoid complicated code fragments like comprehensions, I usually use `while "forever":` or `while FOREVER:` (where forever was set to True before). In these case, I don't need them to understand exactly why the loop is indeed infinite, I just want them to know it is. But all these solutions are available right now, without any syntax change. About the original proposal, even though I'm not a native English speaker, writing `while:` seems like an wobbling sentence, we are waiting for it to be completed. My mind says "while what?" and tries to find out if it's infinite or if it has to find the condition elsewhere in the code (like some kind of do...until or do...while loop). -Brice ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Re: [Python-ideas] "while:" for the loop
On Wed, Sep 26, 2018 at 1:29 PM Mikhail V wrote: > > On Wed, Sep 26, 2018 at 5:38 AM Chris Angelico wrote: > > > > > > I like saying while "something": where the string describes the loop's > > real condition. For instance, while "moar data": if reading from a > > socket, or while "not KeyboardInterrupt": if the loop is meant to be > > halted by SIGINT. > > > > ChrisA > > if doing so, would not it be more practical > to write is as an in-line comment then? > with new syntax it could be like this: > """ > while: # not KeyboardInterrupt > asd asd asd > asd asd asd > asd asd asd > """ > Similar effect, but I would find it better at least because it would > be highlighted as a comment and not as a string, + no quotes noise. A comment is not better than an inline condition, no. I *want* it to be highlighted as part of the code, not as a comment. Because it isn't a comment - it's a loop condition. ChrisA ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Re: [Python-ideas] "while:" for the loop
On Wed, Sep 26, 2018 at 5:38 AM Chris Angelico wrote: > > > I like saying while "something": where the string describes the loop's > real condition. For instance, while "moar data": if reading from a > socket, or while "not KeyboardInterrupt": if the loop is meant to be > halted by SIGINT. > > ChrisA if doing so, would not it be more practical to write is as an in-line comment then? with new syntax it could be like this: """ while: # not KeyboardInterrupt asd asd asd asd asd asd asd asd asd """ Similar effect, but I would find it better at least because it would be highlighted as a comment and not as a string, + no quotes noise. ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Re: [Python-ideas] "while:" for the loop
On Wed, Sep 26, 2018 at 12:35 PM Michael Selik wrote: > > On Tue, Sep 25, 2018 at 8:46 PM Mikhail V wrote: > > I suggest allowing "while:" syntax for the infinite loop. > > I.e. instead of "while 1:" and "while True:" notations. > > > > My opinion: > > 1. I think it'd definitely improve clarity. > > I prefer the explicit phrase, ``while True:``. Saying "while" without > a condition is strange, like a sentence fragment. The ``while 1:`` > pattern is a carryover from Python 2, when ``True`` was not yet a > keyword. I like saying while "something": where the string describes the loop's real condition. For instance, while "moar data": if reading from a socket, or while "not KeyboardInterrupt": if the loop is meant to be halted by SIGINT. ChrisA ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Re: [Python-ideas] "while:" for the loop
On Tue, Sep 25, 2018 at 8:46 PM Mikhail V wrote: > I suggest allowing "while:" syntax for the infinite loop. > I.e. instead of "while 1:" and "while True:" notations. > > My opinion: > 1. I think it'd definitely improve clarity. I prefer the explicit phrase, ``while True:``. Saying "while" without a condition is strange, like a sentence fragment. The ``while 1:`` pattern is a carryover from Python 2, when ``True`` was not yet a keyword. ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] "while:" for the loop
I suggest allowing "while:" syntax for the infinite loop. I.e. instead of "while 1:" and "while True:" notations. IIRC, in the past this was mentioned in python-list discussions as alternative for the "while True:"/"while 1:" syntax. I even had impression that there was nothing rational against this (apart from the traditional "don't change anything" principle) My opinion: 1. I think it'd definitely improve clarity. Although it's not extremely frequent statement, it still appears in algorithms, where additional noise interfers the reader's concentration. 2. This should become the answer to the "how should I denote an infinte loop?" question. 3. In schools/unis they teach algorithms with Python syntax so it will be easier to remember and to write. Adoption of this spelling is natural and straightforward. 4. It does seem to be a rare case of a very easy to implement syntax change (an expert note needed) Also I have personal sympathy for this because I like to use explicit "break" in the loop body, even though I could use "while expression:" syntax, but I prefer this: while 1: ... if i == N : break instead of this: while i < N: ... It helps me to concentrate by reading, especially in nested loops and those situations with multiple break points. So by me this syntax would definitely achieve an extra +. There were alternative suggestions, e.g. introducing a new keyword "loop", but obviously a new keyword is much harder to do now. I don't know what to add to this actually, I think the idea is understood. I see, it is not the most important problem, but if there is nothing serious against this, I think it's worth it and would be quite a positive (small) improvement and a nice gift to those involved in algorithms. As for statistics - IIRC someone gave statistics once, but the only thing I can remember - "while 1/True" is used quite a lot in the std lib, so the numbers exceeded my expectation (because I expected that it's used mostly in algorithms). Mikhail ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/