Java Programming - Flow Control - Discussion

Discussion Forum : Flow Control - Finding the output (Q.No. 21)
21.
What will be the output of the program?
int I = 0;
label:
    if (I < 2) {
    System.out.print("I is " + I);
    I++;
    continue label;
}
I is 0
I is 0 I is 1
Compilation fails.
None of the above
Answer: Option
Explanation:

The code will not compile because a continue statement can only occur in a looping construct. If this syntax were legal, the combination of the continue and the if statements would create a kludgey kind of loop, but the compiler will force you to write cleaner code than this.

Discussion:
15 comments Page 2 of 2.

Raju said:   1 decade ago
Continue satatement come under only loops.
for (;;).
for (:).
while ().
do while () ;.

Other than it gives compilation error and if you use break than you can use two other places.
block.
switch.

Sireesha said:   1 decade ago
What will be the output of the program?

int I = 0;
label:
if (I < 2) {
System.out.print("I is " + I);
I++;
continue label;
}
i didn't get any idea y this pgm gives compilation error.and thanks for giving this type of online tests to us.

Sireesha said:   1 decade ago
Where can I implement the loop in above program give example ?

Ramu said:   1 decade ago
I would like to know the next number of the following series
1, 2, 6, 30, 60, 130, ?

Ramu said:   1 decade ago
where can i implement the loop in above program give example


Post your comments here:

Your comments will be displayed after verification.