Hi guys and Marry Christmas to all of you who are celebrating!
I'm traying to learn PHP on my own and I am stuck in traying to understand this concept of nested loops and using break/continue in them.
So, can someone please explain to me how this code below is working and why I'm getting result that I don't expect.
Code is:
for($i = 0; $i < 6; $i++) {
for($d = 0; $d < 4; $d++) {
if($d == $i) {
continue 2;
}
echo $d."d <br>";
echo $i."i <br>";
}
}
When I was writing this code I was expecting that result, because of continue 2, will be 4i and 5i. But instead of that I got this 0d,1i,0d,2i,1d,2i,0d,3i,1d,3i,2d,3i,0d,4i,1d,4i,2d,4i,3d,4i,0d,5i,1d,5i,2d,5i,3d,5i.
I really want to how I got this result, I spent whole day traying to explain this to myself and failed miserably.