Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #15601
| Newsgroups | comp.lang.javascript |
|---|---|
| Subject | Re: Semicolons and the do..while statement |
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
| References | <88f8c6ba-bc50-4695-b442-10f1dc377363@o8g2000yqm.googlegroups.com> <503e0c75$0$6219$ba4acef3@reader.news.orange.fr> |
| Message-ID | <XnsA0BE9F9347Aeejj99@194.109.133.133> (permalink) |
| Date | 2012-08-29 13:41 +0000 |
SAM wrote on 29 aug 2012 in comp.lang.javascript:
> Le 29/08/12 08:56, RobG a écrit :
>> The syntax for the do..while statement (ECMA-262 12.6.1[1]) is:
>>
>> do /Statement/ while ( /Expression/ );
>>
>> Noting the trailing semicolon, I expected the following to throw an
>> error:
>>
>> do {} while (false) var x = 3;
>
> var x = 2;
> do { alert(x) } while (x--) var y = 5;
> alert(y);
>
> isn't "understood" as loop on do+while ?
> something like :
>
> var x = 2;
> [ do { alert(x) } while (x--) ] [ var y = 5 ]
> [ instruction 1 ] [ instr. 2 ]
> alert(y);
>
> that loops on the 'while' to do 'do' before to parse the following, no?
> Why to loose time searching a ; when the 'while' is closed by its ")"
[Testing in Chrome:]
var x=2;
do { alert(x) } while (x--) alert(x);
The do-while statement simply ends with the conditional (x--)
the second alert(x) is the next statement showing -1
=============================
Try for fun:
var x=73;
do ; while (x--) alert(x);
This will start an endless loop btw:
var x=-73;
do ; while (x--) alert(x);
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Semicolons and the do..while statement SAM <stephanemoriaux.NoAdmin@wanadoo.fr.invalid> - 2012-08-29 14:35 +0200
Re: Semicolons and the do..while statement "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-08-29 13:41 +0000
Re: Semicolons and the do..while statement SAM <stephanemoriaux.NoAdmin@wanadoo.fr.invalid> - 2012-08-29 17:47 +0200
Re: Semicolons and the do..while statement "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-08-29 17:23 +0000
csiph-web