Hello I am studying for the 1Z0-803 (Oracle Certified Associate, Java SE 7 Programmer) exam and I have the hardest time with following the flow of nested loops. On practice tests I do ok on more complex concepts like polymorphism but I miss over half of question with nested loops. For example:

outer:
            for(int i=0; i<3; i++) {
                for(int j=0; j<2; j++) {
                    if(i == j){continue outer;}
                System.out.println("i=" + i + " , j=" + j);
                }   

            }

I know this outputs
i=1 , j=0
i=2 , j=0
i=3 , j=1
I know this from reading the explanation after getting it wrong. What I am not getting is how is j = 0?
I know this is really simple but I keep missing nested loops especial with labels so any help or advice as to how to approach solving these problems while taking the exam would be greatly appreciated.

No, that's not what it outputs. The actual output is

i=1 , j=0
i=2 , j=0
i=2 , j=1

(all you needed to do is to run it)

Just step through the two loops one step at a time...

i = 0
   j = 0
      i == j, continue outer
i = 1
   j = 0
      print
   j = 1
       i == j, continue outer
i = 2
   j = 0
      print
   j = 1
      print
   j = 2 - exit loop
i = 3 - exit loop
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.