var animal = "dog"
switch (animal) {
case "dog": console.log("yay"); break;
case "cat": console.log("oh"); break;
}
switch(expression) {
case true :
break;
default :
//
break;
}
- var friends = 10
case friends
when 0
p you have no friends
when 1
p you have a friend
default
p you have #{friends} friends
switch(expression)
{
case 1:
do_something();
case 2:
if (x > 0) nextcase 1; // Jump to 1
nextcase; // Jump to the next case.
default:
foo();
}
Switch[expr,
pattern1, code1,
pattern2, code2,
pattern3, code3
]
(case my-num
(5 (display "Five!"))
(0 (display "Zero!"))
(else (display "Not an option")))
match X {
| Y: outln("X is Y")
| Z: outln("X is Z")
| A | B | C: outln("X is A, B, or C")
|: outln("X is not Y, Z, A, B and C")
}
Languages with Switch Statements include JavaScript, C, Java, PHP, Go, C#, PowerShell, Swift, CoffeeScript, Objective-C, Dart, Reason, Pug, Groovy, ABAP, C3, Wolfram Language, Slope, Flow9, X10, Angelscript, Apex, Jule, JS++
Languages without Switch Statements include Lil, progsbase
View all concepts with or missing a hasSwitch measurement
Read more about Switch Statements on the web: 1.