Loops: Why Repetition Matters
Why Loops?
Programming often involves repeating tasks. For example, imagine printing every number from 1 to 10—it’s tedious to write print 10 times! Loops automate such repetition.
The for Loop
A for loop repeats a block of code for a specific number of iterations. Here’s the syntax:
for i := 0; i < 10; i++:
print($"Iteration {i}");
Here’s what happens:
i := 0;
initializes i to 0.i < 10
checks if the condition is true. If not, the loop ends.i++
increments i by 1 after each iteration.