rhai/scripts/for1.rhai

20 lines
490 B
Plaintext
Raw Normal View History

2020-03-16 07:50:12 +01:00
// This script runs for-loops
2021-06-07 08:52:45 +02:00
let arr = [1, true, 123.456, "hello", 3, 42];
2020-03-16 07:50:12 +01:00
2021-06-07 08:52:45 +02:00
for (a, i) in arr {
for (b, j) in ['x', 42, (), 123, 99, 0.5] {
if b > 100 { continue; }
print(`(${i}, ${j}) = (${a}, ${b})`);
}
2020-03-16 07:50:12 +01:00
if a == 3 { break; }
}
2021-12-20 08:18:44 +01:00
//print(a); // <- if you uncomment this line, the script will fail to compile
2020-03-16 07:50:12 +01:00
// because 'a' is not defined here
2021-06-07 08:52:45 +02:00
for i in range(5, 0, -1) { // runs from 5 down to 1
2020-03-16 07:50:12 +01:00
print(i);
}