I have two for loops want exit from two loops my control is at inner loop see the below code
for(condition)
{
for (condition)
{
if(condition)
from here i want to exit from these loops
}
}
JS uses statement labels to give statements identifiers. This is great for use on nested loops, because it can give your inner statement control of what's happening beyond its 'tier' of loop. Statement labels can be used with either the continue or break statements.
So your code can be:
someName:
for(condition)
{
for (condition)
{
if(condition)
if (condition) {
break someName; // exit outer loop
}
}
}
For more info, see MDN "label".
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