Curriculum Basics while and for
while and for
Zig has while (cond) { ... } for condition-driven loops and for (slice) |item| { ... } for iteration. The C-style three-clause for (init; cond; step) is gone — its replacement is while (cond) : (step) { ... } (note the colon-continuation syntax for the step expression). The TS for...of reflex maps directly to Zig's for (...) |item|.
Exercises
9 ready
01
pick one
TypeScript writes while (cond) { ... }. Zig keeps the parens
02
pick one
Zig has no three-clause for (init; cond; step) — its
03
pick one
TypeScript's for...of iterates a collection. Zig's equivalent is
04
fill blanks
Fill the missing keyword. The loop runs while the condition is
05
fill blanks
Fill the missing keyword for the iteration loop. The construct
06
type one line
Type the missing Zig line — the while loop header that counts
07
type one line
Type the missing Zig line — the for loop header that iterates
08
write a program
Write a complete Zig program that uses a while loop with the
09
write a program
Write a complete Zig program that: