For-loop counter other than usize

Hello @smallkirby

There is no way to declare the range type.
See why: Why are range variables always usize? - #2 by IntegratedQuantum

There are two ways to loop: for and while.

  • Cast to the desired type:

    for (0..10) |_i| {
      const i = @as(u32, @intCast(_i));
    }
    
  • Declare the desired type:

    var i: u32 = 0;
    while (i < 10) : (i += 1) {
    }
    

EDIT: added @intCast

2 Likes