itera
Translation status: Tiếng Việt reader-locale proof. Code fences render through the vi pipeline; prose is canonical Latin.
Starts a for-each iteration statement.
Aliases: iterate
Syntax: itera <mode> <expression> <binding> <block>
Category#
control-flow
Related#
Examples#
radix/corpus/itera/cursor-iteratio.fab (canonical · keyword)#
Starts a for-each iteration statement.
# =============================================================================
# itera — Starts a for-each iteration statement.
# =============================================================================
#
# What this teaches:
# • for-each iteration using stream functions — consumes values yielded via
# `cede` from `fiunt` and `fient` functions
# • sync and async stream modes — `fiunt` and `fient` function signatures
#
# Common mistakes:
# • Forgetting that stream functions must use `fiunt` or `fient` and yield
# values with `cede`.
#
# See also: ex, de, ab
# =============================================================================
# itera ex — cursor function return iteration
#
# itera ex <cursor-call> fixum <item> { <body> }
#
# GRAMMAR:
# forInStmt :← 'itera' 'ex' callExpr 'fixum' ident block
# cursorDecl :← funcDecl 'fiunt' | funcDecl 'fient'
#
# EXPECTED OUTPUT:
# Sync cursor values and collected lista of doubled results.
#
# BACKEND:
# Rust lowers `fient` through the async-cursor carrier. Go supports the
# `fiunt` half and reports `fient` as an explicit target gap.
# Multi-value sync stream function that yields values via cede
fn grena(int n) generator → int {
for range 0‥n const i {
yield i
}
}
# Multi-value async stream function that yields values via cede
fn grena_futurum(int n) async_generator → int {
for range 0‥n const i {
yield i
}
}
async_main {
# Direct consumption of cursor yield stream
print "Sync cursor iteration:"
for from grena(3) const num {
print " numerus: §"(num)
}
# Collect all results from cursor function
var _ effecta ← []
for from grena(5) const num {
effecta.appende(num * 2)
}
print "Sync collected:"
print effecta
print "Async cursor iteration:"
for from grena_futurum(3) const num {
print " async numerus: §"(num)
}
}Expected output:
Sync cursor iteration:
numerus: 0
numerus: 1
numerus: 2
Sync collected:
[0, 2, 4, 6, 8]
Async cursor iteration:
async numerus: 0
async numerus: 1
async numerus: 2
radix/corpus/itera/in-functione.fab (canonical · keyword)#
Starts a for-each iteration statement.
# =============================================================================
# itera — Starts a for-each iteration statement.
# =============================================================================
#
# What this teaches:
# • accumulator patterns inside functions — using `itera ex` to compute sums, maxima, and counts
# • combining iteration with conditional logic (`si`) inside the loop body
#
# Common mistakes:
# • Using the wrong iteration keyword — ex for values, de for indices/keys, ab for ranges; mixing them up produces unexpected results.
#
# See also: ex, de, ab
# =============================================================================
# itera ex — accumulator pattern inside functio
#
# itera ex <lista> fixum <item> { <body> }
#
# GRAMMAR:
# forInStmt :← 'itera' 'ex' expr 'fixum' ident block
#
# EXPECTED OUTPUT:
# Sums, maxima, and counts above a threshold for sample listas.
fn summa(list<int> numeri) → int {
var int total ← 0
for from numeri const n {
total ← total + n
}
return total
}
# Assumes non-empty lista (seed from first element)
fn maximum(list<int> numeri) → int {
var int max ← numeri[0]
for from numeri const n {
if n > max {
max ← n
}
}
return max
}
fn supra(list<int> numeri, int limen) → int {
var int int ← 0
for from numeri const n {
if n > limen {
int ← int + 1
}
}
return int
}
main {
const _ numeri ← [1, 2, 3, 4, 5]
print summa(numeri)
print maximum(numeri)
print supra(numeri, 3)
print summa([10, 20, 30])
print maximum([5, 12, 8, 20, 3])
}Expected output:
15
5
2
60
20
radix/corpus/itera/intervallum-gradus.fab (canonical · keyword)#
Starts a for-each iteration statement.
# =============================================================================
# itera — Starts a for-each iteration statement.
# =============================================================================
#
# What this teaches:
# • range iteration with a step value using `per` — controls stride between elements
# • descending ranges with negative step values
# • exclusive (`‥`) vs inclusive (`…`) range bounds with step
#
# Common mistakes:
# • Using a step value that never reaches the end bound — ensure the step direction matches the range direction.
#
# See also: ex, de, ab
# =============================================================================
# itera ab — ranges with step using per
#
# itera ab <start>‥<end> per <step> fixum <item> { <body> }
# itera ab <start>…<end> per <step> fixum <item> { <body> }
#
# GRAMMAR:
# forRangeStmt :← 'itera' 'ab' rangeExpr 'per' expr ('fixum' | 'varia') ident block
#
# EXPECTED OUTPUT:
# none — stdout not pinned for this exemplum.
main {
# Step by 2 (exclusive: 0, 2, 4, 6, 8)
for range 0‥10 step 2 const i {
print i
}
# Step by 2 (inclusive: 0, 2, 4, 6, 8, 10)
for range 0…10 step 2 const i {
print i
}
# Step by 3
for range 0‥15 step 3 const i {
print i
}
# Descending with negative step
for range 10‥0 step -1 const i {
print i
}
# Descending by 2
for range 10‥0 step -2 const i {
print i
}
}radix/corpus/itera/intervallum.fab (canonical · keyword)#
Starts a for-each iteration statement.
# =============================================================================
# itera — Starts a for-each iteration statement.
# =============================================================================
#
# What this teaches:
# • range expressions with exclusive (`‥`) and inclusive (`…`) bounds
# • the explicit `ante` keyword for readability in exclusive ranges
# • descending direction in range iteration
#
# Common mistakes:
# • Confusing ‥ (exclusive upper bound) with … (inclusive upper bound) — off-by-one errors are the most common range bug.
#
# See also: ex, de, ab
# =============================================================================
# itera ab — range expressions with exclusive and inclusive bounds
#
# itera ab <start>‥<end> fixum <item> { <body> } — exclusive end
# itera ab <start> ante <end> fixum <item> { <body> } — explicit exclusive
# itera ab <start>…<end> fixum <item> { <body> } — inclusive end
#
# GRAMMAR:
# forRangeStmt :← 'itera' 'ab' rangeExpr ('fixum' | 'varia') ident block
#
# EXPECTED OUTPUT:
# none — stdout not pinned for this exemplum.
main {
# Basic range (exclusive: 0, 1, 2, 3, 4)
for range 0‥5 const i {
print i
}
# Explicit exclusive with ante (same as ‥)
for range 0 before 5 const i {
print i
}
# Inclusive range with … (0, 1, 2, 3, 4, 5)
for range 0…5 const i {
print i
}
# Range starting from non-zero
for range 5‥10 const i {
print i
}
# Descending direction
for range 5‥0 const i {
print i
}
}radix/corpus/itera/nidificatus.fab (canonical · keyword)#
Starts a for-each iteration statement.
# =============================================================================
# itera — Starts a for-each iteration statement.
# =============================================================================
#
# What this teaches:
# • nested iteration — combining `itera ex` and `itera ab` loops for Cartesian products
# • multiplication tables and coordinate grids as practical examples
#
# Common mistakes:
# • Using ab (range iteration) when ex or de is needed for a collection — each nested itera must independently choose the correct mode.
#
# See also: ex, de, ab
# =============================================================================
# itera ex — nested loops (Cartesian product)
#
# itera ex <collection> fixum <item> { <body> }
# itera ab <start>‥<end> fixum <item> { <body> }
#
# GRAMMAR:
# forInStmt :← 'itera' 'ex' expr 'fixum' ident block
# forRangeStmt :← 'itera' 'ab' rangeExpr 'fixum' ident block
#
# EXPECTED OUTPUT:
# none — row/col pairs, multiplication table, coordinate grids.
#
# BACKEND:
# Go backend does not emit nested itera yet — compile-only smoke.
main {
# Nested lista iteration — 3 × 3 combinations
const _ rows ← [1, 2, 3]
const _ cols ← ["A", "B", "C"]
for from rows const row {
for from cols const col {
print row, col
}
}
# Multiplication table over exclusive ranges 1‥4 (i, j ∈ {1,2,3})
for range 1‥4 const i {
for range 1‥4 const j {
print i, "*", j, "←", i * j
}
}
# Nested ranges: 4 × 4 grid of (x, y) with x, y ∈ {0,1,2,3}
for range 0‥3 const x {
for range 0‥3 const y {
print x, y
}
}
}Expected output:
1 A
1 B
1 C
2 A
2 B
2 C
3 A
3 B
3 C
1 * 1 ← 1
1 * 2 ← 2
1 * 3 ← 3
2 * 1 ← 2
2 * 2 ← 4
2 * 3 ← 6
3 * 1 ← 3
3 * 2 ← 6
3 * 3 ← 9
0 0
0 1
0 2
1 0
1 1
1 2
2 0
2 1
2 2