slige/examples/special_loops.slg

44 lines
906 B
Plaintext

fn main() {
let i = 0;
while i < 3 {
println("hello world");
i += 1;
}
let chars = string_to_array("12435");
for char in chars {
println(string_push_char("", char));
}
let values = array_new::<int>();
array_push(values, 10);
array_push(values, 20);
array_push(values, 30);
let pairs = array_new::<[int]>();
for (let i = 0; i < array_length(values); i += 1) {
let pair = array_new::<int>();
array_push(pair, i);
array_push(pair, values[i]);
array_push(pairs, pair);
}
for pair in pairs {
println("values[" + itos(pair[0]) + "] = " + itos(pair[1]));
}
}
fn string_to_array(value: string) -> [int] {
let result = array_new::<int>();
let length = string_length(value);
for (let i = 0; i < length; i += 1) {
array_push(result, value[i]);
}
result
}