Using Conditionals

Go supports the following two types of conditionals:

  • The if/else blocks

  • The 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 1200+ tech skills courses.