Go Conditions
Go Conditions
Conditions help in decision making. A condition is either true or false.
Go supports the usual comparison operators from mathematics:
- Less than
x < y - Less than or equal
x <= y - Greater than
x > y - Greater than or equal
x >= y - Equal to
x == y - Not equal to
x != y
Additionally, Go supports the usual logical operators:
- Logical AND
x && y - Logical OR
x || y - Logical NOT
!x
You can use these operators or their combinations to create conditions for different decisions.
Go has the following conditional statements:
- Use
ifto specify a block of code to be executed, if a specified condition is true - Use
elseto specify a block of code to be executed, if the same condition is false - Use
else ifto specify a new condition to test, if the first condition is false - Use
switchto specify many alternative blocks of code to be executed - Use
selectis similar to switch but is used for channel communication.

