← All examples

The position beside the item

for 'i', 'x' in lend 'xs' — 'i' is 1, 2, 3 … (a uint64, like every position), 'x' the item there.

for_position.zg
# The position beside the item (owner, 2026-09-29: a): `for 'i', 'x' in lend 'xs'` — 'i' is
# 1, 2, 3 … (a uint64, like every position), 'x' the item there. Position first, as in 'xs'['i'].
MAIN {
    let 'xs' := ["ann", "bob", "cy"];
    for 'i', 'x' in lend 'xs' {
        std::print.useful['i', ". ", 'x', newln];
    }
    let 'scores' := [70, 95, 88];
    let mut 'best_at': uint64 = 0;
    let mut 'best': int32 = 0;
    for 'i', 's' in lend 'scores' {
        if 's' > 'best' { change 'best' = 's'; change 'best_at' = 'i'; }
    }
    std::print.useful["best is ", 'best', " at position ", 'best_at', newln];
    for perm 'n', 'y' in lend 'xs' { }
    std::print.useful["after: ", 'n', " ", 'y', newln];
}
Output
1. ann
2. bob
3. cy
best is 95 at position 2
after: 3 cy