Most of the time, students get confused of the usage of looping. I always say, “Imagine a block of code that prints 10 consecutive numbers. One way of doing it is by printing them one-by-one. That would be easy if printing 10 numbers is the case but if your program needs to print 1000 numbers then that would be a very long program just for printing. The answer to that problem is looping. If you use a loop, you just define a starting point, a condition of where you are going to stop, and the process if it is increasing or decreasing. A block of 1000 codes would just take three to four lines of codes.”
In this program we are going to use a loop called a for loop. I used a variable x to hold the value that will be printed then I declared the starting value and ending value which are inside the range.
Below is my program.
Here is my output:
Thank you for reading this post. 🙂