I was trying to find a way to break nested loops better than this way
var found = false;
for(x=0; x<10; x++){
for(i=0; i<10; i++){
if(i===3){found =true; break;}; //break inner loop
};//end of inner loop (i)
if(found){break;}; // break outer loop
};//end of outer loop for(x)
then I found an answer here recommends to use labels to avoid more breaks and a Boolean like this
//var found = false; // - using labels we saved this Boolean
exitlabel:
for(x=0; x<10; x++){
for(i=0; i<10; i++){
if(i===3){break exitlabel;}; //jump to the label
};//end of inner loop (i)
//if(found){break;}; // - using labels we SAVED this if statement
};//end of outer loop for(x)
but the problem is I can't but the label after the 2 loops to quit them . when I do this the browser tells me it can't find the label ! like this:
for(x=0; x<10; x++){
for(i=0; i<10; i++){
if(i===3){break exitlabel;};
};
};
exitlabel: // ERROR
and butting the label before the loops will make the loops execute again from the beginning , unless I use a if statement and a Boolean right after the label and before the loops to bypass the 2 loops, with something like this
var found = false;
exitlabel:
if(!found){
for(x=0; x<10; x++){
for(i=0; i<10; i++){
if(i===3){found =true; break exitlabel;};
};//end of inner loop (i)
};//end of outer loop for(x)
};// end of if statement
IS there a way to save a Boolean and avoid wrapping my loops inside a IF statement like this ,and just put the label after the 2 loops like C language?
if this is a stupid question , please consider I'm very newbie, thanks.