Conditional statements are used to perform different actions based on different conditions.
A condition can be either true
or false
.
Go supports the usual comparison operators from mathematics:
<
<=
>
>=
==
!=
Additionally, Go supports the usual logical operators:
&&
||
!
You can use these operators or their combinations to create conditions for different decisions.
Go has the following conditional statements:
if
to specify a block of code to be executed, if a specified condition is trueelse
to specify a block of code to be executed, if the same condition is falseelse if
to specify a new condition to test, if the first condition is falseswitch
to specify many alternative blocks of code to be executed截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!