Curriculum Basics while and for exercise 2 · mcq
while and for
Zig has no three-clause for (init; cond; step) — its
replacement is while (cond) : (step) { ... }. The step
expression goes after a colon, before the body. Pick the Zig
translation of this C-style for loop.
TypeScript reference
About this theme
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|.