wood burning stoves 2.0*
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


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Regarding Continue Keyword" Watch "Regarding Continue Keyword" New topic
Author

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;
label1:
for (h = 0; h < 6; h++)
{
label2:
do
{
i++;
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.

Thanks
Regards
Gaurav
Kris Krason
Greenhorn

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="http://krisreviews.com/2006/12/code-complete-second-edition/" target="_blank" rel="nofollow">Code Complete review</a><br /> <br /><a href="http://www.coderookie.com/2006/tutorial/the-pseudocode-programming-process/" target="_blank" rel="nofollow">Pseudocode Programming Process</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regarding Continue Keyword