Skip to main content
Module 2 · Lesson 2 of 57/50 in the course~10 min
Module lessons (2/5)

for: the only loop

Lesson preview5 hands-on exercises readyCourse Go · Module 2 — Flow Control

The three forms of for: three-clause, one-condition (= while), infinitive; use of break and continue.

What you'll learn in this lesson

  • Express any iteration using the three forms of the single keyword for in Go.
  • Control execution with break, continue and labels on nested loops.
  • Update multiple indices in post-clause via multiple assignment instead of comma operator.

Overview

Go has no keywords while nor do-while: all the iterative logic revolves around for, declined in three progressive and essential forms.

continue jumps to the next iteration of the innermost loop, while break exits it. When working on nested matrices or grids you can place a label before the outer for:

Sections covered in this lesson

  1. 1The three forms of for
  2. 2break, continue and label on nested loops
  3. 3Multiple indices with multiple imputation
  4. 4Clean guards continue and filters
  5. 5Guided practice
  6. 6Check for understanding
Pro Lesson · Module 2 — Flow Control

Unlock "for: the only loop" and the full Course Go curriculum

The three forms of `for`: three-clause, one-condition (= while), infinitive; use of `break` and `continue`.

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in Course Go plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.