# Break statements in labelled switches, footgun?

**URL:** <https://ziggit.dev/t/break-statements-in-labelled-switches-footgun/6221>\
**Category:** Brainstorming\
**Tags:** language\
**Created:** [October 2, 2024, 7:21am UTC](https://ziggit.dev/t/break-statements-in-labelled-switches-footgun/6221 "2024-10-02T07:21:51Z")\
**Posts on this page:** 1\
**Showing post:** 18

<div class="post-metadata">

**Author:** ![castholm](https://ziggit.dev/user_avatar/ziggit.dev/castholm/32/1330_2.png) [@castholm](https://ziggit.dev/u/castholm)\
**Post date:** [October 4, 2024, 11:24am UTC](https://ziggit.dev/t/break-statements-in-labelled-switches-footgun/6221/18 "2024-10-04T11:24:14Z")

</div>

> [@chung-leong](#):
>
> Well, the OP of this thread could also have typed in the label for the break and we wouldn’t be having this conversation.

But that still doesn’t explain what the problem with switch-as-loop itself is. The problem in the OP with `break` not targeting the intended block appears to be mostly orthogonal from switch statements as a looping construct. Even before labeled switches, you could already run into similar problems if you had an outer loop containing a nested labeled block:

```zig
for (values) |x| {
    blk: {
        if (x == 100) break :blk;
        doSomething(x);
        break; // oops, we forgot the label
    }
    doSomeOtherThing(x);
}

```

I don’t think that means that labeled blocks should be removed. Perhaps it would be useful if it was a compile error to use unlabeled `continue`s or `break`s in situations where there could be multiple intended targets and the author’s intent is ambiguous?

> [@chung-leong](#):
>
> Why would my brain be on the lookout for this information anyway when `switch` has always meant until now what the name describes–a switch.

If what you mean by this is “Zig switches should not loop because switches in C and C-influenced languages don’t loop”, then that seems like a good example of a local maximum, which is something Zig deliberately strives to avoid.

---

_[View the full topic](https://ziggit.dev/t/break-statements-in-labelled-switches-footgun/6221)._
