File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Can you eplain this code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Can you eplain this code" Watch "Can you eplain this code" New topic
Author

Can you eplain this code

Supriya Nimakuri
Ranch Hand

Joined: May 23, 2006
Posts: 83
I found tht error is with Continue statement...can you explain this. Continue should not be used outside the loop. How can I change this code runnable

public class Example1 {


public static void main(String[] args) {

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
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
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
"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
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
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
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;
}
}
}
}
Supriya Nimakuri
Ranch Hand

Joined: May 23, 2006
Posts: 83
Thanks for explaining the code...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can you eplain this code