+ Start a Discussion
Sunita PSunita P 

break from a for loop

Hello everyone,

I have a quick question about a the Break statement, how does a break statement work in a nested for loop e.g.

for(....1st loop){
    for(.... 2nd loop){
        // I have some condition that should break out of the 2nd for loop and continue with the 1st for loop
       if(...){
           break;
      }
   }//End of 2nd for loop
}// end of first for loop

When I write this code in a class, the end curly brace for the class is showing red, even when the the curly braces are matching correctly.

Please help....Thank you.
 
Akhil ReddyAkhil Reddy
I dn't see any problem in typo here, if you want you cantroll it flow using class variable
Class{
    Boolean breakhere = false;
    for(....1st loop){
    for(.... 2nd loop){
        // I have some condition that should break out of the 2nd for loop and continue with the 1st for loop
       if(...){
           isPresent = true; 
           break;
      }
   }//End of 2nd for loop
}// end of first for loop
}