Question

i want control to come back to "for 2" loop after certain iterations. i only want control to break two for loops(for 3, for 4) and go back to "for 2" and continue execution and

    for (m = 0; m < 67; m++) {                     // for 1

         for (i = 0; i < 89; i++) {                               // for 2
                 statement;

              for (k = 0; k < 53; k++) {                            //for 3

                      for (j = 0; j < 265; j++) {                        //for 4


                          statement;

                        }
                     }
                }
            }
Was it helpful?

Solution

Put a label before loop 2

mybreaklabel:
for2 (...) {
    ...
    for4 (...) {
        ...
        break mybreaklabel;
    }
}

OTHER TIPS

you could try this :

for (m = 0; m < 67; m++) {                     // for 1

     for (i = 0; i < 89; i++) {                               // for 2
             statement;

          for (k = 0; k < 53; k++) {                            //for 3

                  for (j = 0; j < 265; j++) {                        //for 4


                      statement;
                      if(condition)
                        break; // you will be in loop 3

                      }//end loop 4
                     if(condition)
                      break; // you will be in loop 2

                 }//end loop 3
            }
        }

You could use labels

for (m = 0; m < 67; m++) {        // for 1
  LOOP2:
  for (i = 0; i < 89; i++) {      // for 2
    statement;
    for (k = 0; k < 53; k++) {    //for 3
      for (j = 0; j < 265; j++) { //for 4
        statement;
        continue LOOP2
      }
    }
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top