Add "else" clause to loop constructs. #21481
Labels
area-language
Dart language related items (some items might be better tracked at github.com/dart-lang/language).
closed-duplicate
Closed in favor of an existing report
type-enhancement
A request for a change that isn't a bug
Please add an "else" clause to loop constructs.
The else clause would be written as:
It will only be executed when the loop condition fails. An unlabeled break inside the body will break past the else-part. Continues inside the else part can not continue the loop, unlabeled breaks in the else part do not refer to the loop.
This feature would make some algorithms much easier to expression, and avoid the labeled breaks that is often used instead.
Example code:
What I currently have to write:
This also shows a valid rewrite to, e.g., JavaScript.
I'm only aware of one language that currently has this feature: Python.
The text was updated successfully, but these errors were encountered: