2.2. Flow control
If Else
Conditionals in Go are similiar to other programming languages. Notice that there are no round brackets surrounding the condition.
| |
Output:
X is greater or equal to 5
Multiple logical conditions can be combined with && (AND) and || (OR).
Switch
If you are testing one variable for multiple conditions with else if the code can quickly become confusing. In these cases a switch statement can be used. The last default case is equivalent to else.
| |
Output:
Tuesday
Loops
The examples below show the basic loop constructs. We will look at an additional variant in the chapter 2.6. Slices.
For - Classical
| |
Output:
0
1
2
3
4
While equivalent
| |
Output:
0
1
2
3
4
Last modified May 29, 2024: Merge pull request #205 from acend/renovate/actions-checkout-digest (cc47d9a)