011_while.zig 875 B

12345678910111213141516171819202122232425262728293031323334
  1. //
  2. // Zig 'while' statements create a loop that runs while the
  3. // condition is true. This runs once (at most):
  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 means "a equals b"
  14. // a < b means "a is less than b"
  15. // a > b means "a is greater than b"
  16. // a != b means "a does not equal b"
  17. //
  18. const std = @import("std");
  19. pub fn main() void {
  20. var n: u32 = 2;
  21. // Please use a condition that is true UNTIL "n" reaches 1024:
  22. while (???) {
  23. // Print the current number
  24. std.debug.print("{} ", .{n});
  25. // Set n to n multiplied by 2
  26. n *= 2;
  27. }
  28. // Once the above is correct, this will print "n=1024"
  29. std.debug.print("n={}\n", .{n});
  30. }