Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

can I assign a default value to a python while loop?

I’ve got a while loop of the form:

while temp is True:
    do stuff
    if the outcome is what I want:
        temp = False

I seem to use this construct quite often. So my question is whether there is a way I can initialise temp in the while statement itself, rather than have to precede this with temp = True?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use:

while True:
    do stuff
    if the outcome is what I want:
        break
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading