Go language conditional statement

A conditional statement requires the developer to decide whether to execute the specified statement by specifying one or more conditions and by testing whether the condition is true, and executing another statement if the condition is false.

The following figure shows the structure of a conditional statement in a programming language:

Sr.No Statement & Description
1 If statement

An if statement consists of a Boolean expression followed by one or more statements.

2 if...Else statement

An optional else statement can be used after the if statement, and the expression in the else statement is executed when the Boolean expression is false.

3 nested if statements

You can embed one or more if or else if statements in an if or else if statement.

4 switch statement

The switch statement is used to perform different actions based on different conditions.

5 select statement

A select statement is similar to a switch statement, but select randomly executes a runnable case. If there is no case to run, it will block until there is a case to run.