Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Go language conditional statement


May 11, 2021 Go


Table of contents


Go language conditional statement

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:

Go language conditional statement

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.