Chris Rebert wrote:
On Wed, Jul 15, 2009 at 3:50 PM, Jan Kaliszewskizuo@chopin.edu.pl wrote:
The issue has been coming back repeatedly:
How we could elegantly and pythonic'ly avoid repeating ourselves if we need the control flow structure that e.g. in PASCAL has the form:
repeat ... until CONDITION
In Python we must use while-loop in not very DRY (Don't Repeat Yourself) manner:
SOME ACTIONS HERE ... while CONDITION: THE SAME ACTIONS AGAIN ...
You can fix that by just writing it as:
while True: SOME ACTIONS HERE if not CONDITION: break
If we were going to add 'repeat' then it could be:
repeat: SOME ACTIONS HERE while CONDITION
If 'while' starts a loop it ends with a colon and the body of the loop follows either on the same line or indented on the next lines. If 'while' ends a 'repeat' loop it doesn't end with a colon and there isn't anything following on the same line or indented on the next lines.