• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

continue

 
xie li
Ranch Hand
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 481
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 146
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for your suggestion!
Karthik Rajashekaran
 
xie li
Ranch Hand
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic