omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / tasks / loops-continue / loops-continue.om
| 1 | note Rosetta Code task "Loops/Continue": https://rosettacode.org/wiki/Loops/Continue |
| 2 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | om2 |
| 4 | text nl "\n" |
| 5 | text sep ", " |
| 6 | note emit writes every byte of a to stdout; a short write is retried, an error exits 1 |
| 7 | fn emit a view uchar * to void |
| 8 | o = ulong 0 |
| 9 | while lt o len a bound 4096 |
| 10 | k = write 1 a o sub len a o |
| 11 | if le k 0 |
| 12 | exit 1 |
| 13 | end |
| 14 | o = add o ulong k |
| 15 | end |
| 16 | end |
| 17 | note emitu writes n in decimal; 20 digits hold every ulong |
| 18 | fn emitu n ulong to void |
| 19 | d = new uchar 20 0 |
| 20 | i = ulong 20 |
| 21 | v = n |
| 22 | while true bound 20 |
| 23 | i = sub i 1 |
| 24 | put d i uchar add rem v 10 48 |
| 25 | v = div v 10 |
| 26 | if eq v 0 |
| 27 | break |
| 28 | end |
| 29 | end |
| 30 | emit part d i sub 20 i |
| 31 | end |
| 32 | note 1 to 10; after a multiple of 5 a newline and continue, otherwise a separator |
| 33 | fn main to int |
| 34 | for k ulong 10 |
| 35 | i = add k 1 |
| 36 | emitu i |
| 37 | if eq rem i 5 0 |
| 38 | emit nl |
| 39 | continue |
| 40 | end |
| 41 | emit sep |
| 42 | end |
| 43 | ret 0 |
| 44 | end |