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 1 of 2.

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

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

Uday said:   8 years ago
@Ramu.

The answer is 212.

Paparao said:   8 years ago
What is a label? What is its function?
(1)

Dipika said:   9 years ago
@Ruba.

The Output is:

5
0

Riya said:   1 decade ago
@Ramu.

Your answer may be 160 after 130 I think.

Ashis said:   1 decade ago
What is label: specified in the program?

Avinash said:   1 decade ago
What is label here please give clearly explain?

Ruba said:   1 decade ago
public static void main(String args[])
{
int i=5,j=8;
j=j||(i++&&13);
System.out.println(i);
System.out.println(j);
}

What will be the output of this coding?

Ranjeet said:   1 decade ago
What is label: here. Please clearly explain?


Post your comments here:

Your comments will be displayed after verification.