Php - Nested Loop, Break Inner Loops and Continue Main Loop

I have the following loop, and I want continuea while loop when the check inside the inner loop matches the condition. I found a solution here (which I applied in the following example), but this is for c#.

    $continue = false;
    while($something) {

       foreach($array as $value) {
        if($ok) {
          $continue = true;
           break;
           // continue the while loop
        }

           foreach($value as $val) {
              if($ok) {
              $continue = true;
              break 2;
              // continue the while loop
              }
           }
       }

      if($continue == true) {
          continue;
      }
    }

Does PHP have its own path to the continuemain loop when the inner loops were break-ed out?

+4
source share
2 answers

( ) , , continue, break. continue :

while($something) {

   foreach($array as $value) {
    if($ok) {
       continue 2;
       // continue the while loop
    }

       foreach($value as $val) {
          if($ok) {
          continue 3;
          // continue the while loop
          }
       }
   }
}
+10

, continue, foreach, . continue in situ .

while($something) {

    foreach($array as $value) {
        if($ok) {
            continue;    // start next foreach($array as $value)
        }

        foreach($value as $val) {
            if($ok) {
               break 2;    // terminate this loop and start next foreach($array as $value)
            }
        }
    }

}

RE:

while($something) {

    if($somevalue) {
        // stop this iteration
        // and start again at iteration + 1
        continue;    
    }


}
0

Source: https://habr.com/ru/post/1606630/


All Articles