A type with its own next returning optional[…] is walked by for.
iterators.zg
# Iterators (owner, 2026-10-08/09): a type with its own `next` returning `optional[…]` is walked by# `for`. `fn Counter.next` belongs to `Counter` and is called `Counter.next[…]` ("`b`"); `for` takes# the iterator with `lend.mut` (it remains, used up as far as the loop went) or `give` (gone after)# ("`c`"). `optional` is the base's: `optional.value[…]` / `optional.none`, matched bare.structCounter{now:int32,stop:int32}fnCounter.next[lent.mut'c':Counter]->optional[int32]{if'c'.nowequal_to'c'.stop{returnoptional.none;}change'c'.now='c'.nowplus1;returnoptional.value['c'.now];}structForever{n:int32}fnForever.next[lent.mut'f':Forever]->optional[int32]{change'f'.n='f'.nplus1;returnoptional.value['f'.n];}MAIN{letmut'c':=Counter[now=0,stop=5];matchCounter.next[lend.mut'c']{value'x'{std::print.useful["by hand: ",'x',newln];}none{std::print.useful["empty",newln];}}for'x'inlend.mut'c'{if'x'equal_to4{break;}std::print.useful["lent: ",'x',newln];}for'x'ingive'c'{std::print.useful["given: ",'x',newln];}letmut'f':=Forever[n=0];forperm'y'inlend.mut'f'{if'y'equal_to3{break;}}std::print.useful["stopped at ",'y',newln];}