Along similar lines, you could also use the fact that Python does lazy-evaluation to make a do-while which forward-references variables: ``` enter_dw = True while enter_dw or (condition_with_vars_not_defined_the_first_time_through): enter_dw = False define_those_vars() ``` Sketch of a use case: get user to input a number greater than 3. ``` enter_dw = True while enter_dw or x <= 3: enter_dw = False x = int(input("enter a number greater than 3: ")) ``` Though the enter_dw variable is a bit clunky. Tangentially, using this same pattern you could also turn `for x in range(10)` into a C-style for loop ``` x = 0 while x < 10: do_something() x += 1 ``` so you have more control of x inside the loop (ie not just incrementing each cycle like the range). ---- On Tue, 01 Mar 2022 12:59:26 -0600 Kevin Mills <kevin.mills226@gmail.com> wrote ----
If you don't like:
while True: ... if whatever: break
One thing I've seen people do is:
condition = True while condition: ... condition = whatever
You can use it if you really hate `while True` loops with `break`. _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/4BSR3Y... Code of Conduct: http://python.org/psf/codeofconduct/