Break out of non-loops

# Sebastian Malton (6 years ago)

An HTML attachment was scrubbed... URL: esdiscuss/attachments/20171027/d77af46b/attachment

# Sébastien Doeraene (6 years ago)

This is already possible:

$ node

console.log('one'); foo: { console.log('two'); break foo;

console.log('three'); }; console.log('four') one two four

# Andreas Rossberg (6 years ago)

That is already supported in JS, for all statements. Even

label: break label;

is legal in JavaScript, and a convoluted way to write a nop.

# J Decker (6 years ago)

On Fri, Oct 27, 2017 at 8:47 AM, Sébastien Doeraene <sjrdoeraene at gmail.com>

wrote:

This is already possible:

$ node

console.log('one'); foo: { console.log('two'); break foo; console.log('three'); }; console.log('four') one two four

probably just me, but this makes it very unobvious where the break goes to... I'd rather see as a matter of style

console.log('one'); do{ console.log('two'); break; console.log('three'); }while(false); console.log('four')

but again; probably just my C basis.

# liorean (6 years ago)

The places where break and continue would be most interesting to me in non-loops would be for dynamic flow control in nested functions or in callbacks, for example to use in mapping or folding functions, not in statement context with lexical blocks and labels. Look at Ruby's next/break/redo/retry for what I mean.

# Isiah Meadows (6 years ago)

That is a whole different deal, closer to Python's StopIteration than standard control flow.