Hi,
Can someone please explain this to me
This is a question from the Khalid's mock
test.
What is the output if the following code is run?
<pre>
public class Q28fd {
public static void main(
String args[]) {
int counter = 0;
l1:
for (int i=10; i<0; i--) {<br /> l2:<br /> int j = 0;<br /> while (j < 10) {<br /> if (j > i) break l2;<br /> if (i == j) {<br /> counter++;<br /> continue l1;<br /> }<br /> }<br /> counter--;<br /> }<br /> System.out.println(counter);<br /> }<br /> }<br /> </pre><br /> Among the answers one of the option is
It will fail to compile<br /> But when selected the answer says it is false.<br /> I tested the exact code, and the compile error listing is below.<br /> <font color=red><br /> Q28fd.java:7: A declaration cannot be labelled: l2<br /> int j = 0;<br /> ^ <br /> Q28fd.java:9: No label definition found for l2.<br /> if(j>i) break l2;
^
I just wanted to know if this needs to be listed to the mock exam errata.
Thnx
Ajay