Control Flow Switch
Start course
2h 17m

If you're thinking about engineering the next big dotcom application then you should seriously consider using Go!! 

The Go Programming Language is without doubt one of the hottest languages to learn, particularly in this cloud native era. More and more companies are adopting Go to engineer highly performant, stable and maintainable applications. Popular projects such as Docker, Kubernetes, Terraform, Etcd, Istio, InfluxDB have all been built successfully using Go!! 

This introductory level training course is designed to bring you quickly up to speed with the many key features that the Go programming language provides. You'll also learn how to setup your own Go development environment - consisting of the Go toolchain, Visual Studio Code, and several related Go based extensions - all to ensure that you are able to be productive writing your own source code.

We’d love to get your feedback on this course, so please give it a rating when you’re finished. If you have any queries or suggestions, please contact us at

Learning Objectives

By completing this course, you will:

  • Learn about what makes Go a great language
  • Learn how to install the Go toolchain
  • Learn how to setup Visual Studio Code to edit and debug Go programs
  • Learn how to work with the Go Playground to test and run snippets of Go code
  • Learn and understand the basic Go language syntax and features
  • Learn how to use the Go tool chain commands to compile, test, and manage Go code
  • And finally, you’ll learn how to work with and manage Go modules for module dependency management

Intended Audience

This course is intended for:

  • Anyone interested in learning the Go Programming Language
  • Software Developers interested in using Go to compile and test Go based applications
  • DevOps practitioners looking to learn about Go to support Go based applications


To get the most from this course, you should have at least:

  • A basic understanding of software development and the software development life cycle

Source Code

All sample Go source code as used and demonstrated within this course can be found here:


- [Jeremy Cook] The switch statement provides another form of control flow. There are a couple alternates ways in which it can be implemented. 

In the example displayed here, the first switch statement, covering lines eight to 15, shows how the switch statement can be declared with both a statement and expression. The following case statements are then evaluated from top to bottom with the first one matching being where the program flow goes. 

The second switch statement, covering lines 19 to 26, shows how to use a switch statement with a missing expression. Using this approach allows the following case statements to evaluate Boolean-based expressions. In this case, the score variable is tested to see whether it exists within a certain banded range. This particular switch statement also demonstrates utilizing the default case, which will be used if none of the previous case statements match. Running this example results in the following messages being printed out, orange for the first switch statement and pro for the second switch statement. 

In summary, you've just observed how switch cases are evaluated from top to bottom with the first matching case having its statements then executed, and if no matching cases are found and a default case is defined, then its statements are executed. A couple of notes, unlike Java, you don't need to provide the break keyword to prevent fallthrough. By default, the switch statement will exit once the first matching case statements have been executed. However, the break keyword is still available and can be useful for particular requirements. Go does have the fallthrough keyword to allow fallthrough from one case to the next case. Switch statements should be preferred to chained if/else statements, mainly for readability.

About the Author
Learning Paths

Jeremy is a Content Lead Architect and DevOps SME here at Cloud Academy where he specializes in developing DevOps technical training documentation.

He has a strong background in software engineering, and has been coding with various languages, frameworks, and systems for the past 25+ years. In recent times, Jeremy has been focused on DevOps, Cloud (AWS, Azure, GCP), Security, Kubernetes, and Machine Learning.

Jeremy holds professional certifications for AWS, Azure, GCP, Terraform, Kubernetes (CKA, CKAD, CKS).

Covered Topics