Treatment of nested 'break'

Dan Smith daniel.smith at
Thu May 10 18:45:12 UTC 2018

> On May 9, 2018, at 2:32 PM, Brian Goetz <brian.goetz at> wrote:
> The model here is that break is like return; the type of its operand must agree with the enclosing method.  

Okay, I think I've successfully wrapped my mind around the two views we're discussing.

One is that value break is like label break: it's a transfer of control to a specific target, in this case the innermost surrounding switch expression. The only thing that would prevent you from legally breaking with that target would be a control flow barrier—a construct that simply doesn't support passing control to the surrounding context.

The other is that value break is like empty break or value return: a transfer of control to the immediately surrounding "break" thing. At that point, if you happen to have provided the wrong flavor of payload, it's an error.

I think these are both valid explanations, with different outcomes, but anyway it's fair to say that it would be confusing to have the latter perspective and then try to explain how a value break can get past a surrounding 'for' loop.

My problem: if you're deep in the guts of nested loops and you want to break to an enclosing target, you can use a label. Or if you want to return from the method, you can use the 'return' keyword.* What do you do if you want to break with a value?

(*We don't strictly need a 'return' keyword in the language at all. 'break' could unambiguously serve the same purpose, with the same limitations as in a switch block. But there would be lots of pitchforks if we tried imposing those limitations on method bodies.)

More information about the amber-spec-experts mailing list