If block labels

something like

'label: if condition {
  ...
  break 'label; // will exit this if-else chain as if it was enclosed in a labeled block
}

'label: if condition {
  ...
  continue 'label; // will jump to the next if in this if-else chain
}
else if other_condition {
}

(edit) I don't mean this to be a feature of "adding labels to expressions", only adding labels to ifs, so you can break out of them or continue to the next in the chain

I'm still of the opinion that this feature requiring a block is a good thing.

Please describe your motivation, not just a syntax idea. What are you hoping to accomplish?

(Maybe this would be better with become or a finite state machine syntax or ...)

1 Like

for break 'label nested block just looks weird, especially with double indentation, continue 'label would be just a new feature for if-else chains

(read your comment on gh) I don't mean adding labels for bare expressions, just for ifs, same way as they mark loops and blocks

I could see allowing break 'label for any ExpressionWithBlock (expressions that don't require a ; when used as a statement) being reasonable. More than that or continue for non-looping constructs seems extremely awkward.

4 Likes

Don't start from the feature; start from the motivation.

What's the code you're writing today? How do you have to structure it? What makes functions not a good choice? What makes this come up frequently?

It's it's rare then if it "looks weird" that's fine.

13 Likes

break and continue are always just "skipping" things. break skips the rest of the loop (or the rest of the block) and continue skips the rest of the iteration. But this new usage of continue is not just skipping the block - it executes the else clause, which otherwise would not get executed.

6 Likes