omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / drafts / rosettacode / loops-continue.wiki
| 1 | =={{header|Omegese}}== |
| 2 | {{works with|omc|sha256 2c824805, aien-dev/omega-mv e5b32567, Linux AArch64}} |
| 3 | Omega has no imports, so the small output helpers (<code>emit</code> and friends) are part of the program. |
| 4 | <syntaxhighlight lang="text"> |
| 5 | om2 |
| 6 | text nl "\n" |
| 7 | text sep ", " |
| 8 | note emit writes every byte of a to stdout; a short write is retried, an error exits 1 |
| 9 | fn emit a view uchar * to void |
| 10 | o = ulong 0 |
| 11 | while lt o len a bound 4096 |
| 12 | k = write 1 a o sub len a o |
| 13 | if le k 0 |
| 14 | exit 1 |
| 15 | end |
| 16 | o = add o ulong k |
| 17 | end |
| 18 | end |
| 19 | note emitu writes n in decimal; 20 digits hold every ulong |
| 20 | fn emitu n ulong to void |
| 21 | d = new uchar 20 0 |
| 22 | i = ulong 20 |
| 23 | v = n |
| 24 | while true bound 20 |
| 25 | i = sub i 1 |
| 26 | put d i uchar add rem v 10 48 |
| 27 | v = div v 10 |
| 28 | if eq v 0 |
| 29 | break |
| 30 | end |
| 31 | end |
| 32 | emit part d i sub 20 i |
| 33 | end |
| 34 | note 1 to 10; after a multiple of 5 a newline and continue, otherwise a separator |
| 35 | fn main to int |
| 36 | for k ulong 10 |
| 37 | i = add k 1 |
| 38 | emitu i |
| 39 | if eq rem i 5 0 |
| 40 | emit nl |
| 41 | continue |
| 42 | end |
| 43 | emit sep |
| 44 | end |
| 45 | ret 0 |
| 46 | end |
| 47 | </syntaxhighlight> |
| 48 | {{out}} |
| 49 | <pre> |
| 50 | 1, 2, 3, 4, 5 |
| 51 | 6, 7, 8, 9, 10 |
| 52 | </pre> |