Programming Course for Beginners - ZedLX

The Easiest Online Computer Programming Course, for Free

Iteration [9/10]

In this example, value of the loop control variable n is increased by 3 in each iteration. In other words, the step of the for loop equals 3.
[Run the program]

The step of the for loop is specified after the symbols += .

If a loop is counting downwards, then the step can be specified after the symbols -= .

Exercise:

1. Change the loop so that the variable n starts from value 50 and then decreases by 3 in each iteration.

Solution

for #n= 50 .. 1  -=3

Loading...