←back to thread

Zig is hard but worth it

(ratfactor.com)
401 points signa11 | 1 comments | | HN request time: 0.204s | source
Show context
askkk ◴[] No.36152113[source]
In new last version 0.10.1 it seems that for is not working with two arguments?

  const std = @import("std");
  const expect = std.testing.expect;

  test "for basics"  {
    const items = [_]i32 {4,5,3,4,0};
    var sum: i32 = 0;
    for(items, 0.. ) |value,_| {
      sum += value;
     }
     try expect(sum == 16);
  }

  ubuntu 22.04, snap zig version 0.10.1 , 
  zig test 1.zig produces:

  1.zig:7:12: error: expected ')', found ','
  for(items, 0.. ) |value,_| {
           ^
Edited: To update, I tried snap, but using snap install --classic --beta zig is a security risk because it can change the system and is not sandboxed.
replies(1): >>36153140 #
1. EscapeFromNY ◴[] No.36153140[source]
For loop syntax was changed since 0.10.1.

Zig 0.10.1:

    for(items) |value| {}
    for(items) |value, index| {}
Zig 0.11-dev:

    for(items) |value| {}
    for(items, 0..) |value, index| {}
    for(as, bs, cs, ds, 0..) |a, b, c, d, index| {}