Conditional statements
The conditional statement structure of the Go language is as follows:
The go language's conditional statements are similar to other languages. Briefly listed below:
1, if statement, Boolean expression does not require parentheses
If boolean expression {/* Executes when the Boolean expression is true */}
2. If...else statement
The If boolean expression {/* Executes when the Boolean expression is true */}Else{/* whenthe Boolean expression is False */}
3. If statement nesting
If Boolean expression 1{/* executes when Boolean expression 1 is true */if Boolean expression 2 {/* isexecuted when Boolean expression 2 is true */}
}
4. Switch statement
Slightly different from other languages, var1 can be any type, val1 and val2 must be the same type as var1. A case statement does not require a break, only matches and executes one of the items, and ends the switch statement
Switch{case val1:... case val2:... default:... }
Go Language Introduction (iii)