Enhanced for Loops
Why Enhanced Loops?
Enhanced loops are simpler when iterating over collections, like arrays or ranges. They’re especially useful for focusing on elements instead of indices.
Here’s the syntax:
for i, elem in 0..10:
print($"Index {i}, Value {elem}");
i is the index (starts at -1).
elem is the current value.
Use enhanced loops when dealing with collections and ranges, but stick to normal loops for more complex conditions.