• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

confusing answer

 
Rick Reumann
Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm confused by this answer in JQ+ concerning labeled breaks:

A break statement with label Identifier attempts to transfer control to the enclosing labeled statement that has the same Identifier as its label; this statement, which is called the break target, then immediately completes normally. In this case, the break target need not be a while, do, for, or switch statement.

I'm not sure what they are saying here. I've used breaks in switches, and in loops but have never seen a break target not be a while, do, for, or switch statement with or without a label. Can someone show me an example of this? Or maybe I'm just totally missing what this quote is all about.
Thanks for the help.
Rick
 
sonir shah
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Rick..I am confused now..
Can any one clear our doubts? what does the statement is trying to say?..
I guess Rick is missing something..not sure.
Any Comments, Ranchers?.
Sonir
 
Rick Reumann
Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds like they are saying you could place a label anywhere in your program and break to it, although I can't seem to duplicate nor have I ever even seen it or heard of it before.

[ February 01, 2002: Message edited by: Rick Reumann ]
 
R K Singh
Ranch Hand
Posts: 5384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
It means that you can use break without loops or switch. but when u are using it without loops or switch then u must give it label i.e.
{
// codes
break;
}
this will give compile error ... though it looks like it should come out of that block.
label01: {
// codes
break label01;
}
this will compile and works fine ..
CMIW
HTH
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic