Is it possible to use the break
function to exit several nested for
loops?
If so, how would you go about doing this? Can you also control how many loops the break
exits?
In a nested loop, a break statement only stops the loop it is placed in. Therefore, if a break is placed in the inner loop, the outer loop still continues. However, if the break is placed in the outer loop, all of the looping stops.
No, don't spoil it with a break .
There are two steps to break from a nested loop, the first part is labeling loop and the second part is using labeled break. You must put your label before the loop and you need a colon after the label as well. When you use that label after the break, control will jump outside of the labeled loop.
No, don't spoil it with a break
. This is the last remaining stronghold for the use of goto
.
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