Google News
logo
Golang - Interview Questions
Explain about switch statement in Golang?
A switch statement is a multi-way branch record. It gives an effective way to assign the execution to various parts of code based upon the utility of the expression. Go language holds two types of switch statements they are
 
Expression switch : expression switch in Golang is the same as the switch statement in C, C++, Java languages, It gives an effortless way to dispatch execution to various parts of code which is based upon the value of the phrase.
 
Syntax :
switch optstatement; optexpression

{

case exp1: statement

case exp2: statement

…..

default: statement

}

Type switch :
A Type switch is utilized when you require to match types. In this switch, the case includes the type which is operating to compare with the type existing in the switch expression.
 
Syntax :
switch optstatement; type switchexpression

{

case type1: statement

case type2: statement

…..

default: statement

}
Advertisement