interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / tests / compiler / progs / nested.osc

27 lines · 664 bytes Raw Blame History
1// entry: find_pair grid_walk
2// nested loops with early return inside loops.
3fn find_pair(target: i32) -> i32 {
4 for i in 0 .. 20 {
5 for j in 0 .. 20 {
6 if (i as i32) * 20 + (j as i32) == target {
7 return (i as i32) * 100 + (j as i32);
8 }
9 }
10 }
11 return -1;
12}
13
14fn grid_walk(n: u8, stop: u16) -> u16 {
15 let mut acc: u16 = 0;
16 let mut i: u8 = 0;
17 while i < n bound 12 {
18 let mut j: u8 = 0;
19 while j < i bound 12 {
20 acc = acc + (i as u16) * (j as u16);
21 if acc == stop { return 9999; }
22 j = j + 1;
23 }
24 i = i + 1;
25 }
26 return acc;
27}