Label statement moveable

Sébastien Doeraene sjrdoeraene at gmail.com
Wed May 20 20:38:09 UTC 2015


Hi,

On Wed, May 20, 2015 at 7:46 PM, Emanuel Allen <emanuelallen at hotmail.com>
wrote:

> So my first attempt example would actually be rewritten to:
> var i;
> foo:{
>   if(typeof i!=='number') break;
>   i+=1;
> }
> I =0;
> {
> if (i < 5);
>   continue foo;
> }
>
> console.log(i);//log 4
>
> Again the true aim for this is to lower function calls.
>

And what about this, which is the *exact* equivalent of your code, without
even a label:

var i = 0;
do {
  if (typeof i !== 'number') break;
  i += 1;
} while (i < 5);
console.log(i);

(Btw, in this instance, the "typeof" test is not necessary at all. I left
it there to better see the connection with the original code.)

You really don't need what you think you need. If you want to "lower
functions", you can just as well inline them *where they're supposed to be
called*, instead of above or at any arbitrary place, which nulls out the
need for "goto" statements.

I also fail to see whether you're approaching this problem from the point
of view of a) write this by hand, or b) the output of a compiler. Your text
suggests a), but the code can obviously be written easily in the do..while
form I wrote over there, in a much more readable way, so the write-by-hand
hypothesis seems weird, which suggests b). Could you make this clearer?

Cheers,
Sébastien
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150520/4f913d1d/attachment.html>


More information about the es-discuss mailing list