Proposal: switch statement multiple

J Decker d3ck0r at gmail.com
Thu Feb 21 02:37:31 UTC 2019


On Fri, Feb 15, 2019 at 8:02 PM Juan Pablo Garcia <sarabadu at gmail.com>
wrote:

> I think it would be great if the switch statement allows multiple argument
>
> Example
> Switch(a,b)
> Case: 1,true
> Case: 1,false
> Case: 2,true
> ....
>
>
> Switch (true, true)
> Case: isPremium,  true
> Case: isBasic, hasCredit
> Case: isBasic, !hasCredit
>
>
>
Can't you just 'do that' ?

var isPremium = false;
var isBasic = !isPremium;
var hasCredit = true;

switch( true  ) {
   case isPremium:
      console.log( "one" );
      break;
   case isBasic && hasCredit:
      console.log( "two" );
      break;
   case  isBasic && !hasCredit  :
      console.log( "three" );
      break;
   default:
      console.log( "default" );
      break;
}



var o = {a:true, b:true}

switch( true  ) {
   case o.a == true && o.b == true :
      console.log( "one" );
      break;
   case o.a == false &&  o.b == true :
      console.log( "two" );
      break;
   case o.a == true &&  o.b == false :
      console.log( "three" );
      break;
   default:
      console.log( "default" );
      break;
}



> Maybe case: default, true
>
> Look forward to read yours views.
>
>
>
> I used to code in cobol and was very useful the sintax
> COBOL example:
> Evaluate a also b
> When 1 also true
> When any also false
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20190220/0600da08/attachment.html>


More information about the es-discuss mailing list