Java Programming - Flow Control - Discussion

Discussion :: 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;
}

[A]. I is 0
[B]. I is 0 I is 1
[C]. Compilation fails.
[D]. None of the above

Answer: Option C

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.


Ramu said: (Dec 9, 2010)  
where can i implement the loop in above program give example

Ramu said: (Dec 9, 2010)  
I would like to know the next number of the following series
1, 2, 6, 30, 60, 130, ?

Sireesha said: (Mar 25, 2011)  
Where can I implement the loop in above program give example ?

Sireesha said: (Mar 25, 2011)  
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.

Raju said: (Mar 31, 2012)  
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.

Ranjeet said: (Mar 18, 2013)  
What is label: here. Please clearly explain?

Ruba said: (Jul 23, 2013)  
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?

Avinash said: (Sep 17, 2013)  
What is label here please give clearly explain?

Ashis said: (Jun 30, 2015)  
What is label: specified in the program?

Riya said: (Aug 31, 2015)  
@Ramu.

Your answer may be 160 after 130 I think.

Dipika said: (Feb 14, 2017)  
@Ruba.

The Output is:

5
0

Paparao said: (Apr 28, 2017)  
What is a label? What is its function?

Uday said: (May 20, 2017)  
@Ramu.

The answer is 212.

Atul said: (Jun 26, 2017)  
Yes @Uday.

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

Raj Patel said: (Aug 14, 2018)  
I think label is only for a loop. Am I right?

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.