What if you could tell your code to count for you instead of writing every step yourself?
Why For-in loop with ranges in Swift? - Purpose & Use Cases
Imagine you want to count from 1 to 10 and print each number. Doing this by writing each number one by one is like writing a long list by hand.
Writing each step manually takes a lot of time and is easy to mess up. If you want to change the range, you must rewrite everything, which is slow and boring.
Using a for-in loop with ranges lets you tell the computer to count for you automatically. You just say the start and end numbers, and the loop does the rest.
print(1) print(2) print(3) print(4) print(5)
for number in 1...5 { print(number) }
This lets you repeat tasks easily and change the number of repetitions quickly without extra work.
Counting days in a calendar app to show each day number automatically instead of typing each day manually.
Manually repeating code is slow and error-prone.
For-in loops with ranges automate counting and repeating tasks.
They make code shorter, easier to read, and flexible.