O'Reilly logo

Get Programming with Go by Nathan Youngman and Roger Peppé

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required