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.

Riya said:   1 decade ago
@Ramu.

Your answer may be 160 after 130 I think.

Dipika said:   9 years ago
@Ruba.

The Output is:

5
0

Uday said:   8 years ago
@Ramu.

The answer is 212.

Atul said:   8 years ago
Yes @Uday.

1 2 6 30 60 130 (212)
1 4 24 30 70 82
3 20 6 40 12

Raj Patel said:   7 years ago
I think label is only for a loop. Am I right?


Post your comments here:

Your comments will be displayed after verification.