Curriculum Basics while and for exercise 3 · mcq
while and for
TypeScript's for...of iterates a collection. Zig's equivalent is
for (slice) |item| { ... } — the |item| part is the loop's
payload-capture syntax, common to several Zig constructs. Pick
the Zig translation.
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|.