aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes continue outer loop 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 "continue outer loop" Watch "continue outer loop" New topic
Author

continue outer loop

saied ims
Ranch Hand

Joined: Jun 21, 2005
Posts: 109
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

Joined: Feb 02, 2006
Posts: 2023

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

Joined: Oct 25, 2005
Posts: 216
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
 
jQuery in Action, 2nd edition
 
subject: continue outer loop