Skip to content

cotrSwitch

Creates a switch statement

Aliases:

  • cotrSwitch
  • switch
  • switchStatement
  • select
  • case

cpp

switch (variable) {
case value1:
// Your code here
break;
case value2:
// Your code here
break;
default:
// Your code here
}

csharp

switch (variable) {
case value1:
// Your code here
break;
case value2:
// Your code here
break;
default:
// Your code here
}

dart

switch (variable) {
case value1:
// Your code here
break;
case value2:
// Your code here
break;
default:
// Your code here
}

go

switch variable {
case value1:
// Your code here
break
case value2:
// Your code here
break
default:
// Your code here
}

haskell

case variable of
pattern1 -> expression1
pattern2 -> expression2
_ -> defaultExpression

java

switch (variable) {
case value1:
// Your code here
break;
case value2:
// Your code here
break;
default:
// Your code here
}

javascript

switch (variable) {
case value1:
// Your code here
break;
case value2:
// Your code here
break;
default:
// Your code here
}

javascriptreact

switch (variable) {
case value1:
// Your code here
break;
case value2:
// Your code here
break;
default:
// Your code here
}

perl

case variable {
when value1
# Your code here
when value2
# Your code here
else
# Your code here
}

php

switch variable) {
case value1:
// Your code here
break;
case value2:
// Your code here
break;
default:
// Your code here
}

powershell

Terminal window
switch (variable) {
value1 {
# Your code here
break
}
value2 {
# Your code here
break
}
default {
# Your code here
}
}

ruby

case variable
when value1
# Your code here
when value2
# Your code here
else
# Your code here
end

rust

match variable {
value1 => {
// Your code here
},
value2 => {
// Your code here
},
_ => {
// Your code here
}
}

shellscript

Terminal window
case variable in
pattern1)
// Your code here
;;
pattern2)
// Your code here
;;
*)
// Your code here
;;
esac

swift

switch variable {
case value1:
// Your code here
break
case value2:
// Your code here
break
default:
// Your code here
}

typescript

switch (variable) {
case value1:
// Your code here
break;
case value2:
// Your code here
break;
default:
// Your code here
}

typescriptreact

switch (variable) {
case value1:
// Your code here
break;
case value2:
// Your code here
break;
default:
// Your code here
}