Latest web development tutorials

Go language conditional statements

Conditional statements require developers to specify one or more conditions, and tested to determine whether a condition is true whether to perform a specified statement, and in the case of the condition is false in the implementation of other statements.

The following figure shows the structure of the program language conditional statement:

Go language provides the following conditional statement:

Statements description
if statement if after a statementby the Boolean expression followed by one or more statements.
if ... else statement You can use the optionalelse statement if statement,else statement is false expression performs Boolean expressions.
if nested statements You can embed one or more ofif or else ifstatementiforelse ifstatement.
switch statement switch statement is used to perform different actions based on different conditions.
select statement select statement is similar to a switchstatement, but the execution will randomly select a running case. If there is no case to run, it will be blocked until the case can be run.