Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Break & Continue at the same time

I have a nested loop like so:

while(1){

    while($something){
        break & continue;
    }
    // More stuff that I don't want to process in this situation
}

I want to break out of the 2nd while loop and continue the 1st loop from the start (without finishing the 1st loop). Is this possible without using variables?

like image 463
nick Avatar asked Sep 15 '12 04:09

nick


1 Answers

You can continue 2; in your inner loop to continue the outer loop from the beginning.

http://php.net/manual/en/control-structures.continue.php

continue accepts an optional numeric argument which tells it how many levels of enclosing loops it should skip to the end of. The default value is 1, thus skipping to the end of the current loop.

like image 61
jimp Avatar answered Nov 07 '22 05:11

jimp