May 11, 2021 Go
A conditional statement requires the developer to execute another statement by specifying one or more conditions and by testing whether the condition is true to decide whether to execute the specified statement and, in the case of a condition false.
The following illustration shows the structure of conditional statements in the program language:
The Go language provides several conditional judgment statements:
Statement | Describe |
---|---|
The if statement | An if statement consists of a Boolean expression followed by one or more statements. |
if... Else statement | The if statement can be followed by an optional else statement, and the expression in the else statement is executed when the Boolean expression is false. |
If nested statements | You can embed one or more if or else if statements in an if or else if statement. |
Switch statement | Switch statements are used to perform different actions based on different conditions. |
Select statement | Select statements are similar to switch statements, but select randomly executes a runable case. If there is no case to run, it will block until there is a case to run. |