Your files never leave your device
Advertisement

For Loops

Loops are used to repeat tasks without repeating code. The for loop is great when you know how many times you want to loop.

The Standard For Loop

A for loop has three parts: initializer (runs once), condition (checked before each run), and incrementor (runs after each run).

Try It Yourself

        

Looping Arrays

Loops are incredibly useful for going through lists (arrays). You can use a modern for...of loop for a cleaner syntax.

Try It Yourself

        

Practice

Challenge 1: Write a loop that counts down from 10 to 1.

Related Guides

Sponsored Utility
While You're Here
Sponsored Recommendations
Advertisement