It does allow you to avoid a fallthrough at the end of the case.

On Sat, Sep 20, 2025, 8:12 AM Dean Schulze <[email protected]> wrote:

> I don't think it was included in the language spec to be a substitute for
> an else in a case statement.
>
> On Saturday, September 20, 2025 at 4:49:56 AM UTC-6 Dan Kortschak wrote:
>
>> On Sat, 2025-09-20 at 12:24 +0200, Jan Mercl wrote:
>> > On Sat, Sep 20, 2025 at 12:05 PM Dean Schulze
>> > <[email protected]> wrote:
>> >
>> > > The break keyword terminates execution of a select statement, but
>> > > is there any real use for break in a select / case statement?
>> >
>> > For example:
>> >
>> > loop:
>> >         for ... {
>> >                 switch ... {
>> >                 case foo:
>> >                         ...
>> >                 case bar:
>> >                         break loop
>> >                 }
>> >         }
>> >
>>
>> Also, it means that you can avoid an else block, instead breaking at
>> the end of the true block of an it statement
>>
>> select {
>> case v <- c:
>> if trueCase(v) {
>> do stuff.
>> break
>> }
>> // false case
>> do other stuff.
>> ...
>> }
>>
>> --
> 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 [email protected].
> To view this discussion visit
> https://groups.google.com/d/msgid/golang-nuts/e8d9bd75-44fe-4280-a550-772efc6c32fbn%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/e8d9bd75-44fe-4280-a550-772efc6c32fbn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/golang-nuts/CAD53Lr5KKc9rp7d4gx3Xvh4mtBnRRcuufXJ%3DyhEWq32%3DcFpwoQ%40mail.gmail.com.

Reply via email to