php - Nested Loop, Break Inner Loops and Continue The Main Loop
After reading the comment to this question (which was deleted by its author) and did a little research, I found that there is also parameter for continue
just like break
. We can add number to the continue
like so:
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 } } }}
I think as you are not running the continue
until you have processed the complete inner foreach it is irrelevant. You need to execute the continue
in situ and not wait until the end of the loop.
Change the code to this
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: Your comment
while($something) { if($somevalue) { // stop this iteration // and start again at iteration + 1 continue; }}