Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #15600 > unrolled thread

Re: Semicolons and the do..while statement

Started bySAM <stephanemoriaux.NoAdmin@wanadoo.fr.invalid>
First post2012-08-29 14:35 +0200
Last post2012-08-29 17:23 +0000
Articles 4 — 2 participants

Back to article view | Back to comp.lang.javascript

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  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

#15600 — Re: Semicolons and the do..while statement

FromSAM <stephanemoriaux.NoAdmin@wanadoo.fr.invalid>
Date2012-08-29 14:35 +0200
SubjectRe: Semicolons and the do..while statement
Message-ID<503e0c75$0$6219$ba4acef3@reader.news.orange.fr>
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 ")"


-- 
Stéphane Moriaux avec/with iMac-intel

[toc] | [next] | [standalone]


#15601

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2012-08-29 13:41 +0000
Message-ID<XnsA0BE9F9347Aeejj99@194.109.133.133>
In reply to#15600
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)

[toc] | [prev] | [next] | [standalone]


#15602

FromSAM <stephanemoriaux.NoAdmin@wanadoo.fr.invalid>
Date2012-08-29 17:47 +0200
Message-ID<503e39ac$0$6177$ba4acef3@reader.news.orange.fr>
In reply to#15601
Le 29/08/12 15:41, Evertjan. a écrit :
>
> Try for fun:
>
> var x=73;
> do ; while (x--) alert(x);
>
> This will start an endless loop btw:

that seems normal, no ?
same as :

do{} while(x--)   // will do nothing 73 times (or by there)
alert(x)          // x would be -1, no?



-- 
Stéphane Moriaux avec/with iMac-intel

[toc] | [prev] | [next] | [standalone]


#15605

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2012-08-29 17:23 +0000
Message-ID<XnsA0BEC545BEFEeejj99@194.109.133.133>
In reply to#15602
SAM wrote on 29 aug 2012 in comp.lang.javascript:

> Le 29/08/12 15:41, Evertjan. a écrit :
>>
>> Try for fun:
>>
>> var x=73;
>> do ; while (x--) alert(x);
>>
>> This will start an endless loop btw:
> 
> that seems normal, no ?

No

You missquote, leaving out the essential:

var x = -73;

While "normality" is a strange beast, 
it certainly is conforming to the specs.

However, that does not mean there is no gain in studying it.

> same as :
> 
> do{} while(x--)   // will do nothing 73 times (or by there)
> alert(x)          // x would be -1, no?

The new line being just white space to javascript. 



-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web