Go language conditional statement


Conditional statements require developers to specify one or more conditions and decide whether to execute the specified statement by testing whether the condition is true, and execute another statement if the condition is false.

The following figure shows the structure of conditional statements in programming languages:

decision_making.jpg

Go language provides the following types of conditional judgment statements:

switch statement select statement
StatementDescription
if statementif statement consists of a Boolean expression followed by one or more consists of statements.
if...else statement The optional else statement can be used after the if statement , in the else statement The expression of is executed when the Boolean expression is false.
if Nested StatementsYou can embed one or more ## inside an if or else if statement #if or else if statement.
switch statement is used to perform different actions based on different conditions.
select statement is similar to the switch statement, but select will randomly execute a runnable case. If there is no case to run, it will block until there is a case to run.