Go Conditions
Conditional statements are used to perform different actions based on different conditions.
Go Conditions
A condition can be either true or false.
Go supports the usual comparison operators from mathematics:
- Less than
< - Less than or equal
<= - Greater than
> - Greater than or equal
>= - Equal to
== - Not equal to
!=
Additionally, Go supports the usual logical operators:
- Logical AND
&& - Logical OR
|| - Logical NOT
!
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