Using Conditionals
Understand conditionals in Go, including if/else and switch blocks.
Go supports the following two types of conditionals:
The
if/else
blocksThe
switch
blocks
The standard if
statement is similar to other languages with the addition of an optional init
statement borrowed from the standard C-style for
loop syntax.
The switch
statements provide a sometimes-cleaner alternative to if. So, let's jump into the if
conditional.
The if
statements
The if
statements start with a familiar format that is recognizable in most languages:
Get hands-on with 1400+ tech skills courses.