anglais/tests/forp.ang
Neemek ca0031431d
All checks were successful
/ test (push) Successful in 47s
more examples
2026-07-15 21:50:23 +02:00

52 lines
797 B
Text

fn range(from: int, to: int) -> (fn() -> (int, bool)) {
i := from - 1
fn() -> (int, bool) {
i = i + 1
if i >= to {
(-1, false)
} else {
(i, true)
}
}
}
for i in range(0, 10) {
println(i)
}
fn chars(s: str) -> (fn() -> (str, bool)) {
i := 0
fn() -> (str, bool) {
if i >= s.length() {
("", false)
} else {
c := s[i]
i = i + 1
(c, true)
}
}
}
for c in chars("hello") {
print(c)
print(" ")
}
println("")
fn items(l: [any]) -> (fn() -> (any, bool)) {
i := 0
fn() -> (any, bool) {
if i >= l.length() {
(nil, false)
} else {
i = i + 1
(l[i - 1], true)
}
}
}