Manually bumping pos for every character is tedious. We want a loop.
Zig's while works like this:
var n: i64 = 0;
while (n < 3) {
print("{d}\n", .{n});
n += 1;
}
I know Zig also supports placing the n += 1 next to the condition, but I don't feel like supporting that in minizig.
Now use it on source. Walk through with pos += 1, printing each character and its position. Stop when cur() == 0. Then check that cur() is still 0 once you've fallen off.
Suggested string: "hello!". Output should be pos 0: h, pos 1: e, ..., pos 5: !.
pub fn main() void {
source = "hello!";
pos = 0;
while (cur() != 0) {
print("pos {d}: {c}\n", .{ pos, cur() });
pos += 1;
}
print("fell off the end, cur() = {d}\n", .{cur()});
}