Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
52
rated 0 times [  56] [ 4]  / answers: 1 / hits: 61156  / 13 Years ago, mon, september 26, 2011, 12:00:00

Is there a way to assign two different case values to the same block of code without copy and pasting? For example, below 68 and 40 should execute the same code, while 30 is not related.



case 68:
//Do something
break;

case 40:
//Do the same thing
break;

case 30:
//Do something different
break;


Is it incorrect to think something like this should work (even though it obviously doesn't)?



case 68 || 40:
//Do something
break;

case 30:
//Do something else
break;

More From » typescript

 Answers
45

Just put them right after each other without a break



switch (myVar) {
case 68:
case 40:
// Do stuff
break;

case 30:
// Do stuff
break;
}

[#89913] Sunday, September 25, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
zahrafrancisr

Total Points: 176
Total Questions: 105
Total Answers: 99

Location: Svalbard and Jan Mayen
Member since Sun, Sep 25, 2022
2 Years ago
;