Java: break and continue with an optional boolean condition

Brian Goetz brian.goetz at
Mon Jun 11 13:10:43 UTC 2018

Of course, you can do what you are suggesting relatively simply and with 
almost as few characters:

     if (i > 10)

Some languages let you do one-off conditional statements:

     break if (i > 10);

In some cases, this is more readable than the full "if statement" form, 
because it telegraphs the intent to conditionally break a little more 
clearly.  In some cases.

But, I don't find the proposed feature very compelling.  It is neither 
substantially more concise, nor does it open up interesting new avenues 
of expression -- it's mostly a linguistic "hack".

It also constrains with what else we might, in future, want to use as an 
argument to break or continue.  And in fact, expression switches use 
`break` to yield a value for the expression.  (By contrast, this _is_ 
something that opens up interesting new avenues of expression.)  A break 
with a boolean would now be ambigious with break with a value to be 
yielded to a switch.

The `{ statement } if { expression }` form is less problematic in this 
way -- but we still have not been able to convince ourselves that the 
language would be better off with this form than without.


> Would you consider a proposal for extending break and continue with an
> optional boolean condition as reasonable?
> The idea can be summarized in the code example:
>      for (;;) {
>          ...
>          break (i > 10);
>          ...
>          continue (i <= 12);
>          ...
>      }
> //syntax will be:  break/continue [label] [boolean expression];
> This will increase the code readability of for, do and while; and leave
> additional if and some curly brackets out of the picture.
> My arguments for such extension is that it solves the expressiveness
> concerns that Donald E. Knut explain in its article "Structured Programing
> with GOTO statements" by describing the Ole-Johan Dahl proposal for [loop
> while repeat] structure where the condition is not bound to the beginning (
> do...while()) nor to the end of the repeating block (while()...) which
> makes the controlled flow of the program more effective.
> Thank you for your time and consideration!
> With Regards,
> George Radev

More information about the amber-dev mailing list