language · language ·
Collection loops, indexes, reverse, and where
for can iterate collection values, expose an index, start that index elsewhere, reverse the traversal, or filter with where.
Use collection iteration when you care about elements rather than storage positions.
for item in collection { ... }
for item at i in collection { ... }
for item at i = 1 in reverse collection where condition { ... }
for key to value in map { ... }Status: stable
List runtime
Use collection iteration when you care about elements rather than storage positions.
cpu · complete-program · type checked
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])))
project.mech
package = "tests.compiler.kyber.listRuntime"
version = "0.1.0"
backend = "kyber"
osTarget = "windows"
archTarget = "x64"
selfContainedApp = false
Notes and source
reverse appears after in and before the collection expression.
Map loops can bind key to value.
yeho/parser_loops.cpp; language-core.md §8.3