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


Groups > comp.lang.javascript > #9438

Re: Break for last case in switch

From Gene Wirchenko <genew@ocis.net>
Newsgroups comp.lang.javascript
Subject Re: Break for last case in switch
Date 2011-12-19 12:19 -0800
Organization A noiseless patient Spider
Message-ID <vr6ve7tu33omvhcersp2gnlqpjcotc1j92@4ax.com> (permalink)
References (5 earlier) <4eydnfAOdKla9XPTnZ2dnUVZ8qWdnZ2d@giganews.com> <2974255.78QauJFxQc@PointedEars.de> <N5ydnVYLfpXSI3PTnZ2dnUVZ7sOdnZ2d@giganews.com> <2253420.FRqVoOGUtd@PointedEars.de> <Xns9FC0BA0EA7788eejj99@194.109.133.133>

Show all headers | View raw


On 19 Dec 2011 17:17:26 GMT, "Evertjan."
<exjxw.hannivoort@interxnl.net> wrote:

>Thomas 'PointedEars' Lahn wrote on 19 dec 2011 in comp.lang.javascript:
>
>> It makes sense for a lint for ECMAScript implementations to issue a
>> warning if the `break' statement is missing for the last clause (in
>> JavaScriptLint 

>No it does not make sense.

     It does if you are thinking of code maintenance.  Some think that
it is too easy to add a case to the end and forget the break.
Personally, I avoid C-style cases because of the stupidity of
requiring break.

>Despite the name 'switch' suggesting otherwise, 
>the facultativity of the brack and default statements
>make the statement very versatile:
                         ^^^^^^^^^
     This can also be read as "often used to write obfuscated code
(whether deliberately or not)".

>var c=9, a=0, myCondition=true, count=0;
>
>switch(true) {
>   default :
>      alert('default on top');
>   case (c>5):
>      count++;
>   case (a>-7):
>      count++;
>   case (myCondition):
>      count++;
>   case (f===undefined):
>      count++;
>};
>
>alert('Number of conditions satisfied: ' + count); // 4
>
>=========================
>
>btw: 
>The 'default on top' alert does not even fire both in Chrome ansd IE9,
>I would have liked to park "var count-0;" there.

     Why should it?  Since the case (c>5) applies, default does not.

>btw2: 
>Versatile or not, 
>I see no need for the switch() statement for myself,
>I prefer the more logical if-else and complex boolean expressions.  

     As do I.

Sincerely,

Gene Wirchenko

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Break for last case in switch Archos <raul.san@sent.com> - 2011-12-18 11:04 -0800
  Re: Break for last case in switch Stefan Weiss <krewecherl@gmail.com> - 2011-12-18 20:43 +0100
    Re: Break for last case in switch "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2011-12-18 22:13 +0200
    Re: Break for last case in switch Antony Scriven <adscriven@gmail.com> - 2011-12-18 12:21 -0800
    Re: Break for last case in switch Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-12-18 21:37 +0100
      Re: Break for last case in switch Stefan Weiss <krewecherl@gmail.com> - 2011-12-18 21:58 +0100
        Re: Break for last case in switch Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-12-18 22:29 +0100
          Re: Break for last case in switch "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2011-12-18 23:49 +0200
          Re: Break for last case in switch Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-12-18 23:09 +0100
            Re: Break for last case in switch "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2011-12-19 00:32 +0200
          Re: Break for last case in switch Stefan Weiss <krewecherl@gmail.com> - 2011-12-18 23:25 +0100
            Re: Break for last case in switch Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-12-19 00:06 +0100
              Re: Break for last case in switch Stefan Weiss <krewecherl@gmail.com> - 2011-12-19 05:30 +0100
                Re: Break for last case in switch Andrew Poulos <ap_prog@hotmail.com> - 2011-12-19 16:04 +1100
                Re: Break for last case in switch Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-12-19 12:25 +0100
                Re: Break for last case in switch "Evertjan." <exjxw.hannivoort@interxnl.net> - 2011-12-19 17:17 +0000
                Re: Break for last case in switch Gene Wirchenko <genew@ocis.net> - 2011-12-19 12:19 -0800
                Re: Break for last case in switch "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2011-12-19 14:47 +0200
                Re: Break for last case in switch John G Harris <john@nospam.demon.co.uk> - 2011-12-19 15:50 +0000
                Re: Break for last case in switch "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2011-12-19 18:45 +0200
                Re: Break for last case in switch Gene Wirchenko <genew@ocis.net> - 2011-12-19 12:22 -0800

csiph-web