Go language conditional statement


Release date:2023-09-13 Update date:2023-10-13 Editor:admin View counts:209

Label:

Go language conditional statement

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

The following figure shows the structure of conditional statements in a program language:

Image0

Go language provides the following conditional judgment statements:

Statement

Description

If statement

If statement? Consists of a Boolean expression followed by one or more statements.

If…else statement

If statement? You can then use the optional? else statement, where the expression in the else statement executes when the Boolean expression is false.

If nested statement

You can do it in if? Or else if? Embed one or more if in the statement. Or else if? Statement.

Switch statement

Switch? Statement is used to perform different actions based on different conditions.

Select statement

Select? The statement is similar to? switch? Statement, but select randomly executes a runnable case. If there is no case to run, it will block until case is available.

Note: Go has no ternary operator, so it is not supported ?: condition judgment of form.

Powered by TorCMS (https://github.com/bukun/TorCMS).