Curriculum Foundations Conditionals & switch
Conditionals & switch
if/else looks familiar — no parentheses, braces required. The one new shape is the short-statement-if: if err := work(); err != nil { ... }. It scopes a temporary to the condition; you'll see this everywhere in Go. switch exists and doesn't fall through by default — closer to TypeScript's switch with implicit break than to C's.
10 ready
01
pick one TypeScript's if wraps the condition in parentheses and allows
02
pick one Go has a special form of if that lets you declare and check a
03
pick one TypeScript's switch falls through unless you explicitly break
04
pick one Go's switch has two shapes the previous exercise didn't show.
05
fill blanksTheme 4 exercise 2 covered the short-statement-if form. Now write
06
fill blanksEach branch of a Go switch is introduced by the same keyword.
07
type one lineType the Go line that uses the short-statement-if form to
08
type one line Type the Go line that uses a switch statement to call handle()
09
write a program Use Go's switch statement (no fallthrough by default) to print a
10
write a programUse Go's short-statement-if form to scope a temporary to the