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 Regarding Continue Keyword 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 "Regarding Continue Keyword" Watch "Regarding Continue Keyword" New topic

Regarding Continue Keyword

Gaurav Chhabras
Ranch Hand

Joined: Sep 21, 2005
Posts: 126
public class jcp
public static void main(String args[])
int i = 0, j = 0, k = 0,h = 0;
for (h = 0; h < 6; h++)
k = h + i + j;
switch (k)
default: break label1;
case 1: continue label2;
case 2: break;
case 3: break label2;
case 4: continue label2;
case 5: continue label1;
}while (++j<5);
System.out.println(h + "," + i + "," + j);

i have one question regarding above code - :

when it encounters CONTINUE LABEL2 then it will execute the (++j<5) part of the do while loop , but when it encounters CONTINUE LABEL1 then it does not executes (++j<5).
Can you please tell me that why it is so.

Kris Krason

Joined: Aug 05, 2005
Posts: 25
It's because when you do continue label2, then the do {} while loop will move to the next iteration, and while it does, it checks wheter (++j<5) is true.

When you do continue label1, then it goes to next FOR loop, it completely ignores do {} while, it will h++, and check the for loop test.

Kris Krason<br />SCJP1.4 (96%)<br />SCJP1.5 (91%)<br /> <br />See my <a href="" target="_blank" rel="nofollow">Code Complete review</a><br /> <br /><a href="" target="_blank" rel="nofollow">Pseudocode Programming Process</a>
I agree. Here's the link:
subject: Regarding Continue Keyword
It's not a secret anymore!