interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / drafts / rosettacode / loops-foreach.wiki

39 lines · 880 bytes Raw Blame History
1=={{header|Omegese}}==
2{{works with|omc|sha256 2c824805, aien-dev/omega-mv e5b32567, Linux AArch64}}
3Omega has no imports, so the small output helpers (<code>emit</code> and friends) are part of the program.
4<syntaxhighlight lang="text">
5om2
6text nl "\n"
7note the collection: names separated by newlines
8text fruit "apple\nbanana\ncherry\ndate\nelderberry\n"
9note emit writes every byte of a to stdout; a short write is retried, an error exits 1
10fn emit a view uchar * to void
11o = ulong 0
12while lt o len a bound 4096
13k = write 1 a o sub len a o
14if le k 0
15exit 1
16end
17o = add o ulong k
18end
19end
20note foreach visits every newline-terminated element of the collection in order
21fn main to int
22s = ulong 0
23for i ulong len fruit
24if eq get fruit i 10
25emit part fruit s add sub i s 1
26s = add i 1
27end
28end
29ret 0
30end
31</syntaxhighlight>
32{{out}}
33<pre>
34apple
35banana
36cherry
37date
38elderberry
39</pre>