rhai/scripts/for2.rhai

29 lines
423 B
JavaScript
Raw Normal View History

2022-07-24 23:03:35 +08:00
//! This script runs for-loops
2022-01-20 12:06:36 +08:00
2020-05-31 23:44:49 +08:00
const MAX = 1_000_000;
2021-04-04 23:22:45 +08:00
print(`Iterating an array with ${MAX} items...`);
2020-05-31 23:44:49 +08:00
print("Ready... Go!");
let now = timestamp();
let list = [];
2022-01-20 12:06:36 +08:00
// Loop over range
2021-12-15 12:06:17 +08:00
for i in 0..MAX {
2020-05-31 23:44:49 +08:00
list.push(i);
}
2021-06-07 14:52:45 +08:00
print(`Time = ${now.elapsed} seconds...`);
2020-05-31 23:44:49 +08:00
let sum = 0;
2022-01-20 12:06:36 +08:00
// Loop over array
2020-05-31 23:44:49 +08:00
for i in list {
sum += i;
}
2021-04-04 23:22:45 +08:00
print(`Sum = ${sum}`);
2021-06-07 14:52:45 +08:00
print(`Finished. Total run time = ${now.elapsed} seconds.`);