File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "continue outer loop" Watch "continue outer loop" New topic

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){
for ( i=0; i<5; i++) {
for (j=0; j<5; ) {
continue outer;
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}

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
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

i =5 j =1
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: continue outer loop
It's not a secret anymore!