Introduction

Completed

In the previous module, you learned the basics of Go. You explored data types, variables, constants, functions, and packages. You know how to structure the logic of a program and how Go prefers to organize the code. So now you're ready to learn how to write programs in the Go way by using fundamental control flows like if/else, switches, for, and essential functions to handle errors.

If you have previous experience in a programming language that follows most of the C syntax, like C# or Java, a few sections in this module will be straightforward. But in other sections, you'll see nuances where Go differs.

Near the end of the module, you'll find a challenge where you need to apply all the concepts you've learned so far. Later, you'll compare the challenge's solution with your own resolution.

Learning objectives

In this module, you'll:

  • Learn about simple and compound if statements.
  • Learn about switch statements and their features.
  • Use the for keyword to learn about loop statements and their patterns in Go.
  • Use essential functions to handle errors like defer, panic, and recover.

Prerequisites

  • A Go environment that's ready to create applications. Ideally, you should have Go locally installed and configured and also have the Visual Studio Code Go extension installed. Alternatively, you can use the Go Playground.
  • Know how to create and modify .go files.
  • Know how run Go applications by using the terminal prompt.
  • Know how to declare and initialize variables.
  • Know how to create functions.