Languages Features Calendar CSV Lists Blog About Sponsor Add Language
GitHub icon

Switch Statements

Switch Statements

Switch Statements are a feature.

In computer programming languages, a switch statement is a type of selection control mechanism used to allow the value of a variable or expression to change the control flow of program execution via search and map. Switch statements function somewhat similarly to the if statement used in programming languages like C/C++, C#, Visual Basic .NET, Java and exists in most high-level imperative programming languages such as Pascal, Ada, C/C++, C#, Visual Basic .NET, Java, and in many other types of language, using such keywords as switch, case, select or inspect. Switch statements come in two main variants: a structured switch, as in Pascal, which takes exactly one branch, and an unstructured switch, as in C, which functions as a type of goto. Read more on Wikipedia...

Languages with Switch Statements include Java, JavaScript, C, C++, PHP, C#, Go, Swift, PowerShell, Objective-C, Dart, Reason, CoffeeScript, Groovy, ABAP, X10, Wolfram Language, Slope, Angelscript, Jule, Apex, Flow9

Example from JavaScript:
var animal = "dog" switch (animal) { case "dog": console.log("yay"); break; case "cat": console.log("oh"); break; }
Example from Wolfram Language:
Switch[expr, pattern1, code1, pattern2, code2, pattern3, code3 ]
Example from Slope:
(case my-num (5 (display "Five!")) (0 (display "Zero!")) (else (display "Not an option")))
zipper-feature.html 路 switch-statements-feature.html 路 generics-feature.html

View source

PLDB - Build the next great programming language 路 v2022 Day 33 Docs Build Acknowledgements Traffic Today Traffic Trends Mirrors GitHub