I am having the understanding that break statement terminates all nested loops. I have written the following code and it is not working as expected.
<script>
for (i = 0; i < 5; i++) {
for (j = 0; j < 5; j++) {
if (i == 3) {
break;
}
document.write(i + '*' + j + '<br>');
}
}
</script>
Actual Output:
0*0
0*1
0*2
0*3
0*4
1*0
1*1
1*2
1*3
1*4
2*0
2*1
2*2
2*3
2*4
4*0
4*1
4*2
4*3
4*4
As per my understanding, the output should not include 4*0...4*4 because when i == 3, the break should terminate all nested loops.
Expected Output:
0*0
0*1
0*2
0*3
0*4
1*0
1*1
1*2
1*3
1*4
2*0
2*1
2*2
2*3
2*4