015_for.zig 653 B

123456789101112131415161718192021222324252627
  1. //
  2. // Behold the 'for' loop! It lets you execute code for each
  3. // member of an array:
  4. //
  5. // for (items) |item| {
  6. //
  7. // // Do something with item
  8. //
  9. // }
  10. //
  11. const std = @import("std");
  12. pub fn main() void {
  13. const story = [_]u8{ 'h', 'h', 's', 'n', 'h' };
  14. std.debug.print("A Dramatic Story: ", .{});
  15. for (???) |???| {
  16. if (scene == 'h') std.debug.print(":-) ", .{});
  17. if (scene == 's') std.debug.print(":-( ", .{});
  18. if (scene == 'n') std.debug.print(":-| ", .{});
  19. }
  20. std.debug.print("The End.\n", .{});
  21. }
  22. // Note that "for" loops also work on things called "slices"
  23. // which we'll see later.