GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Labelled and Unlabelled controls?? 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 "Labelled and Unlabelled controls??" Watch "Labelled and Unlabelled controls??" New topic
Author

Labelled and Unlabelled controls??

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9394
    
    2

Hi Guys,

Consider the code below from Dan Chisholm,


Can anyone explain the flow??

Thanks in advance.

[ December 07, 2006: Message edited by: Jothi Shankar Kumar Sankararaj ]
[ December 07, 2006: Message edited by: Jothi Shankar Kumar Sankararaj ]

SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Hi Jothi,

perhaps put this line immediately over the switch line:
System.out.printf("i:%d j:%d k:%d%n",i,j,k);

I don't show the flow, only where the breaks and continues jump to.

case 0: continue label2;
does not occur (but would jump in between the } and the while).

case 1: continue label1;
jumps to the third argument of the for loop (after the second semikolon).

case 2: break;
jumps after the } of the switch block. From there to the while (j gets incremented).

case 3: break label2;
jumps after the do block, i.e. after the while condition (so j is not incremented). The while condition belongs to the do block!

case 4: break label1;
jumps after the } of the for loop - System.out.

default does not occur.



Output with the additional line is
i:1 j:0 k:1
i:2 j:0 k:2
i:2 j:1 k:3
i:3 j:1 k:4
3,1



Yours,
Bu.


all events occur in real time
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9394
    
    2

Thanks Bu.
 
GeeCON Prague 2014
 
subject: Labelled and Unlabelled controls??