2

Command and Control

Overview

In this chapter, we’ll use branching logic and loops to demonstrate how logic can be controlled and selectively run. With these tools, you’ll have control of what you do and don’t want to run based on the values of variables.

By the end of this chapter, you will be able to implement branching logic using if, else, and else if; use switch statements to simplify complex branching logic; create looping logic using a for loop; loop over complex data collections using range; use continue and break to take control of the flow of loops; and use goto statements to jump to a labeled statement within a function.

Technical requirements

For this chapter, you'll require Go version 1.21 or higher. The code for this chapter can ...

Get Go Programming - From Beginner to Professional - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.