int i=0; label: if(i<2){ System.out.println("I is :" +i); i++; continue label; } } }
Thanks...
wise owen
Ranch Hand
Joined: Feb 02, 2006
Posts: 2023
posted
0
A label provides a statement with an identifier that lets you refer to it elsewhere in your program. For example, you can use a label to identify a loop, and then use the break or continue statements to indicate whether a program should interrupt the loop or continue its execution.
Supriya Nimakuri
Ranch Hand
Joined: May 23, 2006
Posts: 83
posted
0
Ok..but in this case ...continue is placed inside a loop...but it shows an eroor tht continue is outside the loop
wise owen
Ranch Hand
Joined: Feb 02, 2006
Posts: 2023
posted
0
"If" statement is not a loop statement. Label Statement [ May 28, 2006: Message edited by: wise owen ]
Sreeram Desigan
Greenhorn
Joined: Apr 07, 2006
Posts: 23
posted
0
Hai Supriya, plz send the full code so that v can help u. Contiue can be used only inside loops and if is not a loop. Further the label used for continue should be a loop label.
jerry sharma
Greenhorn
Joined: Mar 30, 2006
Posts: 23
posted
0
hi Supriya ! u can try in this way
public class Example1 { public static void main(String[] args) { int i=0; label: for (i=0;i<5;i++){ System.out.println("I is :" +i); i++; if(i<2) continue label; } } }
vathsala nagaraju
Greenhorn
Joined: May 29, 2006
Posts: 4
posted
0
u can put a loop around it
public class Example {
public static void main(String[] args) {
int i=0; label: while(true) { if(i<2){ System.out.println("I is :" +i); i++; continue label; } } } }