typeover
curriculum

Curriculum Foundations Loops exercise 4 · fill-word

Loops

Exercise 1 covered the classic three-clause for-loop by recognition. Now produce it: fill in the operator that introduces the counter and the function that gets a slice's length.

TypeScript reference
Fill the blanks →

About this theme

Go has one loop keyword: for. Three shapes:

  • for i := 0; i < n; i++ { ... } — classic.
  • for cond { ... } — while-style.
  • for { ... } — infinite, exit via break or return.

No while, no do. continue, break, and labelled breaks behave as you'd expect. The range form is its own theme (next module).