3 ms·
If the compiler has good loop optimizations, the front end can turn foreach into an ordinary loop with a hidden variable: for (x in array) print(x) -
by kazinator 4y ago
If the compiler has good loop optimizations, the front end can turn foreach into an ordinary loop with a hidden variable:
for (x in array)
print(x)
->
const __local0017 = array.len;
for (var __local0018 = 0; __local0018 < __local0017; __local++) {
const x = array[__local0018];
print(x);
}
The middle and back ends will infer that __local0018 doesn't exceed __local0017 which is the length of array and get rid of the bound check.