0PricingLogin
Zig Academy · Lesson

while Loops and continue Expressions

Loop with conditions and step actions.

Repeat with while

A while loop repeats its body as long as a bool condition stays true. It checks the condition before each pass. 🔁

while (i < 5) {
    std.debug.print("{}\n", .{i});
    i += 1;
}

Checked Before Each Pass

Zig tests the condition first, so a while whose condition starts false runs zero times. The body is never guaranteed to execute.

All lessons in this course

  1. if as a Statement and Expression
  2. while Loops and continue Expressions
  3. for Loops over Ranges and Items
  4. break, continue, and Labeled Loops
← Back to Zig Academy