Learn to Program with ZedLX

Free Online Programming Course for Beginners

Basics of for Loops [9/10]

In this example, the loop control variable n increases by 3 in each iteration. This is because the step of the for loop is set to 3.
[Run the program]

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

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

Exercise:

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

Solution

for #n= 50 .. 1  -=3

Loading...