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.

3.1. True or false

3.2. Comparisons

3.3. Branching with if

3.4. Logical operators

3.5. Branching with switch

3.6. Repetition with loops

Summary