Lesson 3. Loops and branches
After reading lesson 3, you’ll be able to
- Have your computer make choices with if and switch
- Repeat code with for loops
- Use conditions for looping and branching
Computer programs rarely read from beginning to end like a novel. Programs are more like Choose Your Own Adventure books or interactive fiction. They take different paths under certain conditions or repeat the same steps until a condition is met.
If you’re familiar with the if, else, and for keywords found in many programming languages, this lesson will serve as a speedy introduction to Go’s syntax.
When Nathan was young, his family would play Twenty Questions to pass the time on long trips. One person would think of something, ...