Hello, so you have a common loop
for($i = 0; $i < $j; ++$i){
}
but you may want to stop the loop before the loop finished, so how do you do this?
You use the break statement!
so using the previous example, lets add a break statement to it
for($i = 0; $i < $j; ++$i){
break;
}
That will end the loop during its first loop, but you can encapsulate it within an if if you wish.
So how do you break out of multiple layers of loops? its quite easy to do. All you need to do is the put the number after the break that is the number of loops to break out of.
for($i = 0; $i < $j; ++$i){
for($a = 0; $a < $b; ++$a){
break 2;
}
}
That's all you need to know




Recent Comments