labelled fallthrough?

129 views
Skip to first unread message

Manlio Perillo

unread,
Nov 24, 2015, 10:03:56 AM11/24/15
to golang-nuts
The go spec, at https://golang.org/ref/spec#ExprSwitchStmt, says:
`In a case or default clause, the last non-empty statement may be a (possibly labeled) "fallthrough" statement to indicate that control should flow from the end of this clause to the first statement of the next clause`.

This is misleading; and to increase confusion there are no example of fallthrough or "labeled" fallthrough.
Today I got the "The Go Programming Language", and there are no examples here, too (if the book index is correct).

I say it is misleading, since following the text I tried to do:
    fallthrough label
but this is not supported by the grammar.
The correct syntax if
    goto label

However the goto does not need to be the last statement, and it is not really a fallthrough.

I think the text should be corrected.


Thanks  Manlio

Ian Lance Taylor

unread,
Nov 24, 2015, 10:10:53 AM11/24/15
to Manlio Perillo, golang-nuts
What correction do you propose?

To clarify, a labelled fallthrough statement is something like

label:
fallthrough

That is, a fallthrough statement may be the target of a goto
statement. You are of course correct that "fallthrough label" is not
supported.

Ian

Manlio Perillo

unread,
Nov 24, 2015, 10:20:00 AM11/24/15
to golang-nuts, manlio....@gmail.com
Il giorno martedì 24 novembre 2015 16:10:53 UTC+1, Ian Lance Taylor ha scritto:
On Tue, Nov 24, 2015 at 7:03 AM, Manlio Perillo
<manlio....@gmail.com> wrote:
> The go spec, at https://golang.org/ref/spec#ExprSwitchStmt, says:
> `In a case or default clause, the last non-empty statement may be a
> (possibly labeled) "fallthrough" statement to indicate that control should
> flow from the end of this clause to the first statement of the next clause`.
>
> [...] 

What correction do you propose?


Add an example.
 
To clarify, a labelled fallthrough statement is something like

    label:
        fallthrough

That is, a fallthrough statement may be the target of a goto
statement.

I really failed to figure this, thanks!
Of course now with an actual example, the text "labeled fallthrough" make sense.


Thanks  Manlio 

Manlio Perillo

unread,
Nov 24, 2015, 10:33:01 AM11/24/15
to golang-nuts, manlio....@gmail.com
Il giorno martedì 24 novembre 2015 16:20:00 UTC+1, Manlio Perillo ha scritto:
Il giorno martedì 24 novembre 2015 16:10:53 UTC+1, Ian Lance Taylor ha scritto:
> [...] 
clarify, a labelled fallthrough statement is something like

    label:
        fallthrough

That is, a fallthrough statement may be the target of a goto
statement.
I really failed to figure this, thanks!
Of course now with an actual example, the text "labeled fallthrough" make sense.

To clarify, I misinterpreted the "(optionally labeled) fallthrough" text with "fallthrough with a label" (the same as with goto).
The reason is that the text "(possibly labeled)" is superfluous (any statement can be labeled), so the fact that a language specification has such an additional text make me assume that there is a special case for the fallthrough statement.


Thanks  Manlio

Matt Harden

unread,
Nov 24, 2015, 12:00:59 PM11/24/15
to Manlio Perillo, golang-nuts
I agree; the best course may be to just remove the "(possibly labeled)" text.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Konstantin Khomoutov

unread,
Nov 24, 2015, 12:12:52 PM11/24/15
to Manlio Perillo, golang-nuts
On Tue, 24 Nov 2015 07:33:01 -0800 (PST)
Manlio Perillo <manlio....@gmail.com> wrote:

> > clarify, a labelled fallthrough statement is something like
> >>
> >> label:
> >> fallthrough
> >>
> >> That is, a fallthrough statement may be the target of a goto
> >> statement.
> >>
> > I really failed to figure this, thanks!
> > Of course now with an actual example, the text "labeled
> > fallthrough" make sense.
> >
>
> To clarify, I misinterpreted the "(optionally labeled) fallthrough"
> text with "fallthrough with a label" (the same as with goto).
> The reason is that the text "(possibly labeled
> <http://localhost:8000/ref/spec#Labeled_statements>)" is superfluous
> (any statement can be labeled), so the fact that a language
> specification has such an additional text make me assume that there
> is a special case for the fallthrough statement.

(Disclaimer: I'm not a native English-speaker either.)

In English, a phrase "(possibly labeled) something" stands for
"something, which might have a label attached to it (or may be not)".

That "-ed" ending of the verb "to label" flexes it to signalize the
possessive case; so a "labeled something" means that that
"something" has been labeled -- by attaching a label to it somehow,
and not the other way round ;-)

Hence I'm afraid your issue with the spec might be a purely linguistic
one.
Reply all
Reply to author
Forward
0 new messages