2022-07-24 17:03:35 +02:00
|
|
|
//! This script runs for-loops.
|
2020-03-16 07:50:12 +01:00
|
|
|
|
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
|
|
|
|
2022-01-20 05:06:36 +01:00
|
|
|
// Loop over array with counter
|
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-02-23 15:48:46 +01:00
|
|
|
}
|
2020-03-16 07:50:12 +01:00
|
|
|
|
|
|
|
if a == 3 { break; }
|
2020-02-23 15:48:46 +01:00
|
|
|
}
|
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
|
2020-02-23 15:48:46 +01:00
|
|
|
|
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);
|
|
|
|
}
|