> ...shouldn't it end the 2nd for loop since if statement is under 2nd for loop... ?
Yes, it should end the 2nd loop and that's what it's doing. To better understand what's going on, I inserted fprintf commands in each loop so you can see the iteration numbers. The first condition is true when j==2 and the second nested condition is true when i==3 (while j is equal to 2).
fprintf('\n i=%d, j=%d',i,j)
fprintf('\n i=%d, j=%d',i,j)
fprintf(' & CONDITION 2: breaking')
You can see (below) that the break condition occurs when i==3 and j==2 and on the next iteration, the i-loop interates to i==4 and the j-loop resets.
0 Comments
Sign in to comment.