let say my code look like below
for(..)
for(..)
for(..){
break; //this will break out from the most inner loop OR all 3 iterated loops?
}
break terminates the execution of a for or while loop. Statements in the loop after the break statement do not execute.
We can use Java break statement in all types of loops such as for loop, while loop and do-while loop.
To break out of a for loop, you can use the endloop, continue, resume, or return statement.
Your example will break out of the innermost loop only. However, using a labeled break statement, you can do this:
outer:
for(..)
for(..)
for(..){
break outer; //this will break out from all three loops
}
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