• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Labelled and Unlabelled controls??

 
Joe Harry
Ranch Hand
Posts: 10110
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Joe Harry
Ranch Hand
Posts: 10110
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bu.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic