Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is while True: a suitable way to repeat a block until an accepted case is reached?

Is while True an accepted method for looping over a block of code until an accepted case is reached as below? Is there a more elegant way to do this?

while True:
    value = input()
    if value == condition:
        break
    else:
        pass
# Continue code here.

Thank you for any input.

like image 891
Thorsley Avatar asked Feb 04 '26 05:02

Thorsley


1 Answers

That's the way to do this in Python. You don't need the else: pass bit though.

Note, that in python 2.x you're likely to want raw_input rather than input.

like image 172
SilentGhost Avatar answered Feb 05 '26 22:02

SilentGhost