On Tue, Mar 5, 2013 at 5:42 AM, David Bruant <[email protected]> wrote:

> Currently, if one wants to do stop an iteration early, he/she has to be
> done one of the following way:
> 1)
>     try{
>
>         [2, 8, 7].forEach(function(e){
>                 if(e === 8)
>                     throw "whatever";
>                 console.log(e)
>         }
>     }
>     catch(e){
>         // do nothing, I just want to catch the error in case the iteration
>         // stopped before traversing all elements
>     }
>

Well... here's what I would do.

    for (var e of [2, 8, 7]) {
        if (e === 8)
            break;   // exiting JS loops since 1994
        console.log(e);
    }

Why not use statements for your procedural code?

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

Reply via email to