Chapter 3. Go Control Flow

Go borrows several of its control flow syntax from the C-family of languages. It supports all of the expected control structures, including if...else, switch, for loop, and even goto. Conspicuously absent, though, are while or do...while statements. The following topics in this chapter examine Go's control flow elements, some of which you may already be familiar with, and others that bring a new set of functionalities not found in other languages:

  • The if statement
  • The switch statement
  • The type Switch
  • The for statement

The if statement

The if statement, in Go, borrows its basic structural form from other C-like languages. The statement conditionally executes a code block when the Boolean expression that follows the if keyword ...

Get Go: Design Patterns for Real-World Projects now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.