function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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
}