13_while3.zig 855 B

1234567891011121314151617181920212223242526272829303132
  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. // The '%' symbol is the "modulo" operator and it
  23. // returns the remainder after division.
  24. if(n % 3 == 0) ???;
  25. if(n % 5 == 0) ???;
  26. std.debug.print("{} ", .{n});
  27. }
  28. std.debug.print("\n", .{});
  29. }