posted 15 years ago
In the above code we have "continue loop" right that is the reason we get 1,2,3,4. I will explain how it is so.
Here loop is a label. Initially when the control comes to first for loop (i.e i for loop here in our case) it has the i value as 1 and then it enters into the j for loop then it prints the i value i.e 1 to the console and then comes to the if statement here x equals 0 condition gets satisfied and hence continue loop statement gets executed. Now the tricky thing happens, the control immediately jumps out of the j for loop and then goes back to the label loop: part and then it increments the i value to 2 now and then checks the condition whether it is lesser than 5 or not and if so it enters into the j for loop again and now this time it prints 2 to the console and in the same fashion the rest of the output 3,4 is displayed on the console.
If we comment line 1 then the control comes to j print statements also and hence j values will also get printed.
I hope my explanation made you clear if not feel free to ask
Regards
Vijay