Curriculum Basics Conditionals (if and switch)
Conditionals (if and switch)
Zig's if looks like TypeScript's: parens around the condition, optional braces around the body. The catch: Zig has no truthy values — the condition must be bool. switch is an expression in Zig (not a statement), so it can be assigned directly. The TS reflex matches Zig here more cleanly than it matches Go.
Exercises
9 ready
01
pick one
TypeScript writes if (cond) { ... } with parens around the
02
pick one
TypeScript chains conditions with else if. Zig keeps the same
03
pick one
Here's where Zig diverges from TypeScript: Zig's switch is an
04
fill blanks
Fill the missing keyword. The condition's first branch handles
05
fill blanks
Fill the missing keyword. The line evaluates a value against
06
type one line
Type the missing Zig line — the if condition that picks
07
type one line
Type the missing Zig line — the switch expression that maps
08
write a program
Write a complete Zig program that:
09
write a program
Write a complete Zig program that uses a switch expression