Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


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| {}




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: