013_while3.zig 825 B

12345678910111213141516171819202122232425262728293031323334
  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. //
  10. // if (other condition) continue;
  11. //
  12. // }
  13. //
  14. // The "continue expression" executes every time the loop restarts
  15. // whether the "continue" statement happens or not.
  16. //
  17. const std = @import("std");
  18. pub fn main() void{
  19. var n: u32 = 1;
  20. // I want to print every number between 1 and 20 that is NOT
  21. // divisible by 3 or 5.
  22. while(n <= 20) : (n += 1){
  23. // The '%' symbol is the "modulo" operator and it
  24. // returns the remainder after division.
  25. if(n % 3 == 0){ continue; }
  26. if(n % 5 == 0){ continue; }
  27. std.debug.print("{} ", .{n});
  28. }
  29. std.debug.print("\n", .{});
  30. }