add loop examples

This commit is contained in:
Matthieu Jolimaitre 2024-10-24 07:03:35 +02:00
parent 6350e4a40f
commit dbeec4ee76
5 changed files with 110 additions and 49 deletions

View file

@ -0,0 +1,4 @@
let msg = "hello world";
msg

22
example/data/loops.mc Normal file
View file

@ -0,0 +1,22 @@
let i = 0;
loop {
i = i + 1;
print("i", i);
if (i > 5) break;
}
fn for(array, op) {
let index = 0;
loop {
let item = array[index];
if (item == none) break;
op(item, index);
index = index + 1;
}
}
for([1, 2, 3], (item, index) => {
print("at index", index, "item", item);
});