# for

Iterate a range or collection

Last updated: 2026-09-09

Package: language | Status: stable

Tags: complete-program, cpu, keyword, loops, yeho

Use a range when you need an index or a predictable number of iterations.

```yh
for
```


## List runtime

Use a range when you need an index or a predictable number of iterations.

Verification: type checked

```yh
list of int values = [2, 4]
values.Add(6)
values[1] = values[1] + 1

int total = 0
for value in values
{
    total = total + value
}

Console.Log(Text.Format("{0}:{1}:{2}", Text.From(values.count), Text.From(values[1]), Text.From(total)))

values.Clear()
values.Add(9)
values.Add(11)
Console.Log(Text.Format("clear:{0}:{1}:{2}", Text.From(values.count), Text.From(values[0]), Text.From(values[1])))



```

Save this beside start.yh as project.mech:

```toml
package = "tests.compiler.kyber.listRuntime"
version = "0.1.0"
backend = "kyber"
osTarget = "windows"
archTarget = "x64"
selfContainedApp = false




```

Extract the example archive beside the yeho and dolphin checkouts. This example requires those source dependencies and a current developer compiler.

```sh
./yeho/build/dolphin-metal/yehoc ./api-examples/word--for/complete --backend cpu-oracle -o /tmp/yeho-example
/tmp/yeho-example
```


< excludes the end; <= includes it.

The step is the next-value expression, such as i + 2.

Source: yeho/parser_loops.cpp parseForStatement; tests/compiler/kyber/range-loop-runtime/start.yh

AI training permission: https://demonhunterlabs.com/ai-use
