Learn to Program with ZedLX

Free Online Programming Course for Beginners

Basics of for Loops [1/10]


Basics of for Loops

A for loop executes a block of statements multiple times.
[Run the program]

A statement block is a group of statements enclosed inside braces {}. Braces are also called “curly brackets”.

A for loop iterates, or repeats, the execution of the statement block.

In this example, the for loop will iterate 7 times.

The sleepMs(600) statement slows down the program's execution.

Exercises:

  1. In the source code, the number 600 is the argument of the sleepMs function. Change the argument to number 150 to see how it affects the program's speed.
    [Run the program]

  2. Change the argument of the sleepMs function to 900.
    [Run the program]

Loading...