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


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

Why terminate do-while with a semi colon?

Started byRobG <rgqld@iinet.net.au>
First post2015-11-13 00:30 -0800
Last post2015-11-14 16:17 +0100
Articles 6 — 4 participants

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


Contents

  Why terminate do-while with a semi colon? RobG <rgqld@iinet.net.au> - 2015-11-13 00:30 -0800
    Re: Why terminate do-while with a semi colon? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-11-13 10:43 +0100
      Re: Why terminate do-while with a semi colon? John Harris <niam@jghnorth.org.uk.invalid> - 2015-11-15 15:12 +0000
    Re: Why terminate do-while with a semi colon? Scott Sauyet <scott.sauyet@gmail.com> - 2015-11-13 10:19 -0800
      Re: Why terminate do-while with a semi colon? RobG <rgqld@iinet.net.au> - 2015-11-14 03:28 -0800
        Re: Why terminate do-while with a semi colon? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-11-14 16:17 +0100

#28882 — Why terminate do-while with a semi colon?

FromRobG <rgqld@iinet.net.au>
Date2015-11-13 00:30 -0800
SubjectWhy terminate do-while with a semi colon?
Message-ID<ff132af3-4cb1-4d31-bdff-6ffcceeab5e6@googlegroups.com>
ECMA-262[1] defines a do-while loop as:

  IterationStatement : do Statement while ( Expression ) ;

I can't find a case where the terminal semicolon is required. Can someone suggest one (or more)?


1. http://ecma-international.org/ecma-262/6.0/index.html#sec-do-while-statement

-- 
RobG

[toc] | [next] | [standalone]


#28883

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2015-11-13 10:43 +0100
Message-ID<XnsA5516D1A79A11eejj99@194.109.6.166>
In reply to#28882
RobG <rgqld@iinet.net.au> wrote on 13 Nov 2015 in comp.lang.javascript:

> ECMA-262[1] defines a do-while loop as:
> 
>   IterationStatement : do Statement while ( Expression ) ;
> 
> I can't find a case where the terminal semicolon is required. Can
> someone suggest one (or more)? 

In my view ALL javascript-statements REQUIRE a terminal semicolon.

["require" in the sense of style if not of necessity]

Now some constructs allow the forgoing of this when a new-line is inserted,
but new-lines are not and never needed in Javascript.

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

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


#28890

FromJohn Harris <niam@jghnorth.org.uk.invalid>
Date2015-11-15 15:12 +0000
Message-ID<d58h4bt0jj8jf8spne5oivab9jaosfs421@4ax.com>
In reply to#28883
On Fri, 13 Nov 2015 10:43:31 +0100, "Evertjan."
<exxjxw.hannivoort@inter.nl.net> wrote:

>RobG <rgqld@iinet.net.au> wrote on 13 Nov 2015 in comp.lang.javascript:
>
>> ECMA-262[1] defines a do-while loop as:
>> 
>>   IterationStatement : do Statement while ( Expression ) ;
>> 
>> I can't find a case where the terminal semicolon is required. Can
>> someone suggest one (or more)? 
>
>In my view ALL javascript-statements REQUIRE a terminal semicolon.

Let's be accurate : In the C family of languages *every* statement
ends with either a semicolon, or a close curly bracket, or a smaller
(encapsulated) statement. 

This regularity is useful, especially when you want to invent a new
kind of statement in one of the languages.


>["require" in the sense of style if not of necessity]

As you say later, not having the semicolon can make a complicated
statement difficult to read, which is a Bad Thing.


>Now some constructs allow the forgoing of this when a new-line is inserted,
>but new-lines are not and never needed in Javascript.

ECMAScript allows you to leave out semicolons in some circumstances,
but in return forces you to remember some awkward cases. E.g
  return
    42;
is two statements, not one.

  John

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


#28884

FromScott Sauyet <scott.sauyet@gmail.com>
Date2015-11-13 10:19 -0800
Message-ID<ada828d7-6b91-4fb2-9828-d67a7369a5d4@googlegroups.com>
In reply to#28882
RobG wrote:
> ECMA-262[1] defines a do-while loop as:
> 
>   IterationStatement : do Statement while ( Expression ) ;
> 
> I can't find a case where the terminal semicolon is required. Can someone
> suggest one (or more)?

No, I can't.  I don't see how there could ever be any ambiguity caused by its absence, which is what I assume you're looking for.

  -- Scott

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


#28885

FromRobG <rgqld@iinet.net.au>
Date2015-11-14 03:28 -0800
Message-ID<1bd5b53e-50b0-4c47-8839-6e95c610d700@googlegroups.com>
In reply to#28884
On Saturday, November 14, 2015 at 4:19:55 AM UTC+10, Scott Sauyet wrote:
> RobG wrote:
> > ECMA-262[1] defines a do-while loop as:
> > 
> >   IterationStatement : do Statement while ( Expression ) ;
> > 
> > I can't find a case where the terminal semicolon is required. Can someone
> > suggest one (or more)?
> 
> No, I can't.  I don't see how there could ever be any ambiguity caused by its absence, which is what I assume you're looking for.

Yes, that's what I was after. Thanks.

-- 
Rob

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


#28886

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2015-11-14 16:17 +0100
Message-ID<XnsA552A5BB38E2Beejj99@194.109.6.166>
In reply to#28885
RobG <rgqld@iinet.net.au> wrote on 14 Nov 2015 in comp.lang.javascript:

> On Saturday, November 14, 2015 at 4:19:55 AM UTC+10, Scott Sauyet wrote:
>> RobG wrote:
>> > ECMA-262[1] defines a do-while loop as:
>> > 
>> >   IterationStatement : do Statement while ( Expression ) ;
>> > 
>> > I can't find a case where the terminal semicolon is required. Can
>> > someone suggest one (or more)?
>> 
>> No, I can't.  I don't see how there could ever be any ambiguity caused
>> by its absence, which is what I assume you're looking for. 

Indeed, it does "work":

var t = '', x = 12;
do { t += x + '\n' } while ( x --> 0 ) alert(t);

However, it looks horrible.

> Yes, that's what I was after. Thanks.

There should be a requirement for Javascript to look well.

-- 
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