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-while / loops-while.om

40 lines · 811 bytes Raw Blame History
1note Rosetta Code task "Loops/While": https://rosettacode.org/wiki/Loops/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 print n and halve it (integer division) while it is above zero, from 1024
32fn main to int
33n = ulong 1024
34while gt n 0 bound 64
35emitu n
36emit nl
37n = div n 2
38end
39ret 0
40end