return when desugaring to closures
David-Sarah Hopwood
david.hopwood at industrial-designers.co.uk
Tue Oct 14 08:29:52 PDT 2008
David-Sarah Hopwood wrote:
> Neil Mix wrote:
>> The for/closures "bug" is definitely a newbie trap, but its pain is
>> not its discovery, but the difficulty of working around it. To me
>> this could be a winning argument against re-binding on each loop,
>> since re-binding precludes the (admittedly dubious) use-case of
>> updating inside the body:
>>
>> for (let i = 0; i < 100; i++) {
>> if (skipAhead) {
>> i += 9;
>> continue;
>> }
>> ...
>> }
>
> The expansions that MarkM and I posted work correctly in that case.
>
> ("Correctly" means what a C programmer would expect :-) To be more
> specific, updates within the body take effect for the instance of
> the variable that is seen by the update expression for the next
> iteration.)
What I meant to say was: Updates within the body affect the value of
the variable instance that is seen by the update expression for the
next iteration.
--
David-Sarah Hopwood
More information about the Es-discuss
mailing list