Curriculum Foundations Loops
Loops
Go has one loop keyword: for. Three shapes:
for i := 0; i < n; i++ { ... }— classic.for cond { ... }— while-style.for { ... }— infinite, exit viabreakorreturn.
No while, no do. continue, break, and labelled breaks behave as you'd expect. The range form is its own theme (next module).
Exercises
9 ready
01
pick one
TypeScript's classic counted loop has three parts in parentheses
02
pick one
Go has no while keyword. The same job is done by for with just
03
pick one
TypeScript writes infinite loops as while (true). Go has a
04
fill blanks
Exercise 1 covered the classic three-clause for-loop by recognition.
05
fill blanks
Exercise 2 covered Go's "for-as-while" shape by recognition. Now
06
type one line
Type the Go line inside the loop that exits early when i reaches
07
type one line
Type the Go line inside the loop that skips nil entries. The
08
write a program
Print the integers 1 to 5 inclusive, one per line, using Go's
09
write a program
Write a program using Go's while-style for (a single