Break out of non-loops

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Break out of non-loops

Sebastian Malton
Something that is very useful that was recently released into Rust was the idea of using a break statement to break out of the current level. This is already the case for loops but in Rust it was extended to all statements encased in {}.

This would make some code a lot easier to understand as it can eliminate flag variables

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Break out of non-loops

Sébastien Doeraene
This is already possible:

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


Cheers,
Sébastien

On Fri, Oct 27, 2017 at 5:40 PM, Sebastian Malton <[hidden email]> wrote:
Something that is very useful that was recently released into Rust was the idea of using a break statement to break out of the current level. This is already the case for loops but in Rust it was extended to all statements encased in {}.

This would make some code a lot easier to understand as it can eliminate flag variables

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Break out of non-loops

Andreas Rossberg-4
In reply to this post by Sebastian Malton
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.

On 27 October 2017 at 17:40, Sebastian Malton <[hidden email]> wrote:
Something that is very useful that was recently released into Rust was the idea of using a break statement to break out of the current level. This is already the case for loops but in Rust it was extended to all statements encased in {}.

This would make some code a lot easier to understand as it can eliminate flag variables

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Break out of non-loops

J Decker
In reply to this post by Sébastien Doeraene


On Fri, Oct 27, 2017 at 8:47 AM, Sébastien Doeraene <[hidden email]> 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.

Cheers,
Sébastien

On Fri, Oct 27, 2017 at 5:40 PM, Sebastian Malton <[hidden email]> wrote:
Something that is very useful that was recently released into Rust was the idea of using a break statement to break out of the current level. This is already the case for loops but in Rust it was extended to all statements encased in {}.

This would make some code a lot easier to understand as it can eliminate flag variables

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Break out of non-loops

liorean
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.
--
David "liorean" Andersson
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Break out of non-loops

Isiah Meadows-2

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


On Fri, Oct 27, 2017, 20:15 liorean <[hidden email]> wrote:
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.
--
David "liorean" Andersson
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss