break
When using break in a loop, you can exit from more than one nested loop buy entering an integer after the break command as in the following example,
<?php
while($x > 0)
{
while($y < 10)
{
break 2;
}
}
while($x > 0)
{
while($y < 10)
{
break 2;
}
}
In the previous example, break 2; will exit both of the while loops, whereas if I had only entered break;, only the while($y < 10) would be executed and the while($x > 0) would continue to loop.
Note: This also works for the continue statement. You can supply an integer to determine how many nested loops to continue through.
[Click to add or edit comments])
Please prepend comments below including a date