Loops and Iteration
LockedLesson 5 of 25 · Syntax · Easy
Finish these first:Conditionals and Branching →Or pass the tests below to unlock it now.
The big idea
Go keeps looping simple: for is the only loop keyword you need to learn. Write the start, stop rule, and step right after for (no parentheses needed): Each pass adds i to coins and increases i by 1 (i++) until i <= 3 is false.
Think of it like this: Think of Go's `for` loop like counting beads: start at 1, keep going while `i <= 5`, and step up by 1 each time.
Read the lesson
Go keeps looping simple: for is the only loop keyword you need to learn.
Write the start, stop rule, and step right after for (no parentheses needed):
coins := 0
for i := 1; i <= 3; i++ {
coins = coins + i // coins becomes 6 (1 + 2 + 3)
}
Each pass adds i to coins and increases i by 1 (i++) until i <= 3 is false.
Quick check
Does Go put parentheses around a `for` loop header?
Your challenge
Inside main(), write a for loop from 1 to 5 that adds each number to total (so total becomes 15).
More learning tools(compare languages, visual guide, related lessons)
Compare with another language
Similar to python.loops (90% overlap). Iteration: for-of in JS, range-for in C++, single 'for' keyword in Go, Iterator/for-in in Rust.
Visual walkthrough
A diagram, a step-by-step animation, and short captions for Loops and Iteration.
Learn this first
- Conditionals and BranchingNot yet