interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / tasks / loops-do-while / loops-do-while.om

43 lines · 851 bytes Raw Blame History
1note Rosetta Code task "Loops/Do-while": https://rosettacode.org/wiki/Loops/Do-while
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5note emit writes every byte of a to stdout; a short write is retried, an error exits 1
6fn emit a view uchar * to void
7o = ulong 0
8while lt o len a bound 4096
9k = write 1 a o sub len a o
10if le k 0
11exit 1
12end
13o = add o ulong k
14end
15end
16note emitu writes n in decimal; 20 digits hold every ulong
17fn emitu n ulong to void
18d = new uchar 20 0
19i = ulong 20
20v = n
21while true bound 20
22i = sub i 1
23put d i uchar add rem v 10 48
24v = div v 10
25if eq v 0
26break
27end
28end
29emit part d i sub 20 i
30end
31note start at 0; add 1 and print, then test: repeat while the value is not a multiple of 6
32fn main to int
33v = ulong 0
34while true bound 100
35v = add v 1
36emitu v
37emit nl
38if eq rem v 6 0
39break
40end
41end
42ret 0
43end