Examples · learn/11-values · 174 of 339
iterator
tin run examples/learn/11-values/iterator.tintype Countdown = { n: int }
// next changes the countdown in place (inout) and gives the next number, or None when done
fn Countdown.next(c: inout Countdown): Option<int> {
if c.n == 0 { return None }
c.n -= 1
Some(c.n + 1)
}
fn main() {
let launch = Countdown { n: 3 }
for t in launch {
print("{t}...")
}
print("liftoff, and launch.n is still {launch.n}")
}