What if you could repeat tasks perfectly without writing the same code again and again?
Why For loop execution model in PHP? - Purpose & Use Cases
Imagine you want to print numbers from 1 to 10. Doing this manually means writing ten separate print statements, one for each number.
This manual way is slow and boring. If you want to print 100 numbers, writing 100 lines is tiring and easy to make mistakes. Changing the range means rewriting many lines.
The for loop lets you write just a few lines to repeat actions many times. It automatically counts and stops when done, saving time and avoiding errors.
<?php print(1); print(2); print(3); // and so on... ?>
<?php for ($i = 1; $i <= 3; $i++) { print($i); } ?>
With the for loop, you can easily repeat tasks many times, making your code shorter, clearer, and easier to change.
Think about sending a greeting message to 50 friends. Instead of writing 50 messages, a for loop sends the message repeatedly with just a few lines.
Manual repetition is slow and error-prone.
For loops automate repeated actions efficiently.
They make code shorter, clearer, and flexible.