Lets print 1 to 5,
The above code would print 1 to 5.
Problem with above approach:
In the above approach, we have declared one variable a and we have assigned the value five times. It is time consuming and resource and effort consuming process. What if we are required to print 1 to 1000. It would become heavy process. So, We can get same result using for loop.
The above code would print 1 to 5. But in this approach, we have done with just three lines. We can get n number of results.
Note: For our understanding purpose, we are printing the result to the alert box but this is wrong approach. Alert is used to alert user.
Print 100 to 1 (hint: var a=100;a>=1;a–)