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.

Consider this

When Nathan was young, his family would play Twenty Questions to pass the time on long trips. One person would think of something, ...

Get Get Programming with Go 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.