This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes continue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "continue" Watch "continue" New topic
Author

continue

xie li
Ranch Hand

Joined: Nov 30, 2005
Posts: 54
public class Cjgreen{
public static void main(String argv[]){
Cjgreen c = new Cjgreen();
c.jgreen();

}
public void jgreen(){
int iNum =1 ;
while(iNum >0){

toffer:
for(int i = 0; i < 3; i ++){
continue toffer;
System.out.println(i);
}
}

iNum --;
}
what is the reslut?
Karu Raj
Ranch Hand

Joined: Aug 31, 2005
Posts: 479
Hi Xie

I dont understand why do you post the questions without even trying by yourself.

Have you ever compile this question.

Try and see then only you will learn lot

not just by posting questions and expecting ranchers to post answer.

,...............

THe answer to the above code is

Compile time error ....If you want to know exactly why do compile yourself and check out

all the best
vipul patel
Ranch Hand

Joined: Oct 16, 2005
Posts: 146
I have copied code snippet as follow.

for(int i = 0; i < 3; i ++){
continue toffer;
System.out.println(i);
}

Now look at the structure of code very carefully. Here

continue toffer;

is not surrounded by the if condition. so System.out.println(i) will not be executed at all. It means that compiler will produce an 'compile time error' that code is not reachable.
xie li
Ranch Hand

Joined: Nov 30, 2005
Posts: 54
thank you for your suggestion!
Karthik Rajashekaran
xie li
Ranch Hand

Joined: Nov 30, 2005
Posts: 54
i know the reslut,but i cannot know how to explain.so
i post it
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: continue
 
Similar Threads
Indefinite loop
Flow control
What is this unreachable error
Autoboxing / unboxing
Powerball program for school, Need to to run program 8 times.