• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
July 21, 2022 |4.1K Views
If and Switch Statement
  Share   Like
Description
Discussion

A switch statement is a multiway branch statement. It provides an efficient way to transfer the execution to different parts of a code based on the value(also called case) of the expression. Go language supports two types of switch statements:

Expression Switch
Type Switch

Both optstatement and optexpression in the expression switch are optional statements.


If both optstatementand optexpression are present, then a semi-colon(;) is required in between them.


If the switch does not contain any expression, then the compiler assume that the expression is true.


The optional statement, i.e, optstatement contains simple statements like variable declarations, increment or assignment statements, or function calls, etc.


If a variable present in the optional statement, then the scope of the variable is limited to that switch statement.


If and Switch Statement : https://www.geeksforgeeks.org/switch-statement-in-go/