+ 1
how to break out all the loops in python
count=0 for i in (1,2): while count<5: count=count+1 hi="*"*count print(hi) if count==5 : while count>=1: count=count-1 yo="*"*count print(yo) can someone tell me how to break out all the loops
3 Respuestas
+ 1
I think using function is better.If you take it in a function ,then you can break out by returning.
0
Use boolean variable to note that the loop is done, and check the variable in the outer loops to execute a second, and third break
0
as stated by others, breaking a loop early isnt really recommended. with that being said, you can break out of a loop early bu inserting “break”.
example:
for i in range(10):
if i == 5:
break
this example will break out of the loop when i reaches 5.