int counter = 0; l1: for (int i=0; i<10; i++) { l2: int j = 0; //compile error while (j++ < 10) { if (j > i) break l2; if (j == i) { counter++; continue l1; } } } System.out.println(counter); when i try to run above code it gives error as follows "not a statement int j = 0;" i am not able to figure out why.
Your topic says "Running the code", do you mean that - not Compiling the code?
This code (which should be enclosed in tags) is incomplete. Is this all the code? No enclosing class? If you need to know what a Java program looks like, then I can transfer this topic over to our Beginners' Forum if you want. [ July 22, 2006: Message edited by: Barry Gaunt ]
Note the label does not have to be on the loop statement but does need to be on a statement, such as an if-else statement, that contains the break statement.
hi Neelesh does it mean that u cant insert any code between label and loop statement. or in other words it means after label there must be loop statement only.