Easy Tutorial
❮ Go Ide Go Select Statement ❯

Go Language Conditional Statements

Conditional statements require developers to specify one or more conditions to be evaluated or tested by the program, and to execute certain statements if the condition is determined to be true, and optionally execute other statements if the condition is false.

The following diagram illustrates the structure of conditional statements in programming languages:

Go language provides the following types of conditional statements:

Statement Description
if statement An if statement consists of a boolean expression followed by one or more statements.
if...else statement An if statement can be followed by an optional else statement, which executes when the boolean expression is false.
nested if statements You can use one if or else if statement inside another if or else if statement(s).
switch statement A switch statement allows a variable to be tested for equality against a list of values.
select statement A select statement is similar to a switch statement but select randomly executes one of the cases available. If no case is ready, it blocks until one is available.

Note: Go does not have a ternary operator, so it does not support the ?: conditional expression.

❮ Go Ide Go Select Statement ❯