One typical case where I end up with at least labeled break
is in a switch
. For example:
loop:
for item := range someChan {
switch item.Type {
case typeA:
// something something
case typeB:
// something something, we should stop processing for some reason
break loop
}
}
Without the label, break
breaks the switch
. Similar of course for for
-in-for
but then you can always argue that it could be refactored to avoid so I’m not going to use that as an example.