There no way to break out of only the inner loop of a next loop in #python?
for i in range(1,100)
while True:
print("whut?")
break # what?
Conversation
Replying to
If you want to break out of the inner While loop, but not the outer for loop. Or if you want to break out of the outer for loop when you are in the middle of the inner loop. Other languages have features for this. stackoverflow.com/a/504983/33264
1
Replying to
for x in range(1,10):
while True:
print(x)
break
This gives me the output (1,2,3,4,5,6,7,8,9) which I would expect. It is breaking out of the inner while loop but staying in the outer for loop. What output would you expect?
Replying to
Not saying the behavior was undefined. Without syntax python lacks, it can only break out of the inner loop then. As a casual reader or a maintenance dev, I'd always assume that the original developer didn't know what would happen-an inner or outer loop break (1) vs (1,2...9)
2
1
There is a similar discussion in JavaScript world, if it is good practice to rely on any feature that would be astonishing to outsiders. For insiders, of course, they have memorized the specifications for the language.
1

