Thread overview
corner case with labled break
Jan 25, 2008
BCS
Jan 25, 2008
BCS
Jan 27, 2008
Jason House
Jan 27, 2008
BCS
January 25, 2008
should this work? (it doesn't now)

|void main()
|{
|	foo: while(true)
|		break foo;   // works
|
|	switch(6)
|	{
|		case 5:
|			while(true)
|				break case 5;   // fails
|
|		case 6:
|			goto case 5;  // works
|
|	}
|}


January 25, 2008
"BCS" <ao@pathlink.com> wrote in message news:55391cb32812d8ca2d7783d0f566@news.digitalmars.com...
> should this work? (it doesn't now)
>
> |void main()
> |{
> | foo: while(true)
> | break foo;   // works
> |
> | switch(6)
> | {
> | case 5:
> | while(true)
> | break case 5;   // fails
> |
> | case 6:
> | goto case 5;  // works
> |
> | }
> |}

It's not in the grammar at all, so I'm not surprised that it doesn't.  It's a tiny feature though.


January 25, 2008
Reply to Jarrett,

> "BCS" <ao@pathlink.com> wrote in message
> news:55391cb32812d8ca2d7783d0f566@news.digitalmars.com...
> 
>> should this work? (it doesn't now)
>> 
>> |void main()
>> |{
>> | foo: while(true)
>> | break foo;   // works
>> |
>> | switch(6)
>> | {
>> | case 5:
>> | while(true)
>> | break case 5;   // fails
>> |
>> | case 6:
>> | goto case 5;  // works
>> |
>> | }
>> |}
> It's not in the grammar at all, so I'm not surprised that it doesn't.
> It's a tiny feature though.
> 

OK, I miss phrased the question: should this be in the grammer?


January 26, 2008
"BCS" <ao@pathlink.com> wrote in message news:55391cb3281338ca2d803bbfda0e@news.digitalmars.com...
>
> OK, I miss phrased the question: should this be in the grammer?

If you're proposing a feature, go ahead and propose it.  I mean, I can't see what I'd use this for, but..


January 27, 2008
Shouldn't the code be:

|void main()
|{
|foo: while(true)
|break foo;   // works
|
|bar: switch(6)
|{
|case 5:
|while(true)
|break bar;   // fails
|
|case 6:
|goto case 5;  // works
|
|}
|}

With embedded switches, "case 5" isn't always unique.  Also, the "break case 5" syntax almost implies to me that it should return to case 6.  I hope that's not what you wanted...
January 27, 2008
Reply to Jason,

> Shouldn't the code be:
> 
> |void main()
> |{
> |foo: while(true)
> |break foo;   // works
> |
> |bar: switch(6)
> |{
> |case 5:
> |while(true)
> |break bar;   // fails
> |
> |case 6:
> |goto case 5;  // works
> |
> |}
> |}
> With embedded switches, "case 5" isn't always unique.

Ok, but that same problem happens with goto case #;

based on that, this should be added:

outer: switch(n)
{
 case 1:
   switch(m)
   {
      case 2: goto outer case 2;
   }
 case 2:
}

>  Also, the
> "break case 5" syntax almost implies to me that it should return to
> case 6.  I hope that's not what you wanted...
> 

Ok so it loops forever, but I /was/ intending that the break exit the loop and continue down the case statment

This would be a more sane example. 

|void main()
|{
| foo: while(true)
|  break foo;   // works
|
| switch(6)
| {
|  case 5:
|   while(true)
|    break case 5;   // fails
|   somthing();
|   break;
|
|  case 6:
|   goto case 5;  // works
|
| }
|}

The point is that case ###: lables act like normal lables elseware, why not with break?