11_while.zig 722 B

123456789101112131415161718192021222324252627282930313233
  1. //
  2. // Zig 'while' statements create a loop that runs while the
  3. // condition is true:
  4. //
  5. // while (condition) {
  6. // condition = false;
  7. // }
  8. //
  9. // Remember that the condition must be a boolean value and
  10. // that we can get a boolean value from conditional operators
  11. // such as:
  12. //
  13. // a == b a equals b
  14. // a < b a is less than b
  15. // a > b a is greater than b
  16. // a !=b a does not equal b
  17. //
  18. const std = @import("std");
  19. pub fn main() void {
  20. var n: u32 = 2;
  21. while ( ??? ){
  22. // Print the current number
  23. std.debug.print("{} ", .{n});
  24. // Set n to n multiplied by 2
  25. n *= 2;
  26. }
  27. // Make this print n=1024
  28. std.debug.print("n={}\n", .{n});
  29. }