13_while3.zig 748 B

123456789101112131415161718192021222324252627282930
  1. //
  2. // The last two exercises were functionally identical. Continue
  3. // expressions really show their utility when used with 'continue'
  4. // statements!
  5. //
  6. // Example:
  7. //
  8. // while (condition) : (continue expression){
  9. // if(other condition) continue;
  10. // ...
  11. // }
  12. //
  13. // The continue expression executes even when 'other condition'
  14. // is true and the loop is restarted by the 'continue' statement.
  15. //
  16. const std = @import("std");
  17. pub fn main() void {
  18. var n: u32 = 1;
  19. // I want to print every number between 1 and 20 that is NOT
  20. // divisible by 3 or 5.
  21. while (n <= 20) : (n+=1) {
  22. if(n % 3 == 0) ???;
  23. if(n % 5 == 0) ???;
  24. std.debug.print("{} ", .{n});
  25. }
  26. std.debug.print("\n", .{});
  27. }