What's the best way to break from inner loop so I reach beginning of the outer loop
while condition:
while second_condition:
if some_condition_here:
get_to_the_beginning_of_first_loop
Right now I got something like
while condition:
while second_condition:
if condition1:
break
if condition1:
continue
Python has the option of an else:
clause for while
loops. This is called if you do not call break
, so these are equivalent:
while condition:
while second_condition:
if condition1:
break
if condition1:
continue
do_something_if_no_break()
and:
while condition:
while second_condition:
if condition1:
break
else:
do_something_if_no_break()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With