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-break.wiki

79 lines · 1343 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 emit writes every byte of a to stdout; a short write is retried, an error exits 1
8fn emit a view uchar * to void
9o = ulong 0
10while lt o len a bound 4096
11k = write 1 a o sub len a o
12if le k 0
13exit 1
14end
15o = add o ulong k
16end
17end
18note emitu writes n in decimal; 20 digits hold every ulong
19fn emitu n ulong to void
20d = new uchar 20 0
21i = ulong 20
22v = n
23while true bound 20
24i = sub i 1
25put d i uchar add rem v 10 48
26v = div v 10
27if eq v 0
28break
29end
30end
31emit part d i sub 20 i
32end
33note a fixed linear congruential generator stands in for a random source (Rosetta asks for
34note random numbers 0..19): x' = (1103515245 x + 12345) mod 2^31, r = (x' / 65536) mod 20.
35note Print r; stop after printing 10; otherwise print the next value too
36fn main to int
37x = ulong 42
38while true bound 1000
39x = and add mul x 1103515245 12345 2147483647
40r = rem div x 65536 20
41emitu r
42emit nl
43if eq r 10
44break
45end
46x = and add mul x 1103515245 12345 2147483647
47emitu rem div x 65536 20
48emit nl
49end
50ret 0
51end
52</syntaxhighlight>
53{{out}}
54<pre>
551
5613
579
581
5916
6013
6117
620
635
645
6512
6614
6714
688
6913
70...
710
725
7315
7414
756
7615
7714
7810
79</pre>