Go language conditional statements

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

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

The Go language provides the following conditional judgment statements:

statementDescription
if statementif statementConsists of a boolean expression followed by one or more statements.
if...else statementif statementcan be followed by an optionalelse statement, the expression in the else statement is executed when the boolean expression is false.
nested if statementYou caniforelse ifembed one or more within the statementiforelse ifstatement.
switch statementswitchThe statement is used to execute different actions based on different conditions.
select statementselectstatement is similar toswitchstatement, but select will randomly execute one runnable case. If no case is runnable, it will block until a case is runnable.

Note: Go does not have a ternary operator, so it does not support?:form of conditional judgment

other extensions