Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

continue outer loop

 
saied ims
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class D{

static int i;
static int j;
public static void main(String [] isl){
outer:
for ( i=0; i<5; i++) {
for (j=0; j<5; ) {
System.out.println("Hello");
j++;
continue outer;
}
System.out.println("outer");
}
System.out.println("Good-Bye");
System.out.println("i ="+i+" j ="+j); why j is still 0 why the second for loop doesnt increment j,even after continue statment it must be incrmented too why the continue make the the second foor loop not incrmented}

}
thanks
 
wise owen
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The above is the output result. j is 1 because the second for will initilize the j value to 0 and only use one time j++ then go to outer-loop.
 
Arun Maalik
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all i would like to say dear that j is not 0 , j will be 1
listen why?

in the inner for loop of your cod

your code like
j++;
continue outer:
in this after 1 increment in j controle will transfer to outer loop and in next itration j will again inialize with 0(see inner loop fundamentals) so after all at last j will only one hope you will have understood
out put of your cod like follow

Hello
Hello
Hello
Hello
HelloGood-Bye
i =5 j =1
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic