Switch statement is a multiway branching which provides an alternative way too lengthy if-else comparisons. It selects a single block to be executed from a listing of multiple blocks on the basis of the value of an expression or state of a single variable. A switch statement using multiple value cases correspond to using more than one value in a single case. This is achieved by separating the multiple values in the case with a comma.
Input : january Output : Winter. Input : september Output : Autumn.
Rather than making different individual cases for months having the same season, we clubbed different months with the same output. This saves us to write redundant pieces of code.
Input : 6 Output : You entered an even number. Input : 5 Output : You entered an odd number.
Instead of writing 10 different cases to check whether the entered number is even or not, we could simply do the same in 2 switch cases using multiple case values.
Input : g Output : Lowercase alphabet character. Input : F Output : Uppercase alphabet character.
- Golang Program that uses String Switch
- Golang Program that Uses Multiple Return Values
- Golang program that uses fallthrough keyword
- Golang program that uses structs as map keys
- Golang program that uses func with variable argument list
- Golang program that uses func with two arguments
- Golang program that uses defer keyword
- Golang Program that Uses Named Return Values and Defaults
- Golang Program that uses func as Local Variable
- Golang Program that switch on floating-point numbers
- Golang Program to Show the Duplicate Case Error in Switch Statement
- Switch Case with Break in For Loop in Golang
- Header files in C/C++ and its uses
- Multiple Interfaces in Golang
- How to use a switch case 'or' in PHP?
- Switch Statement in Go
- Switch case in R
- What is ISL(Inter-Switch Link)?
- What is SMPS(Switch Mode Power Supply)?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.