Repeat: Making a For Loop

google apps script for loop

The For Loop

By Alice Keeler

The For loop is the key to making code really useful. It makes light work of a tedious process of repeating something.


for(var i = 0; i < 10; i++){

What this says is for as long as the middle statement is true, run the code in the middle of the curly braces.

Typically in JavaScript you start counting at zero so you usually define a variable i to start at zero and then increment (i++) by one every time. If you started at i = 1 then i < 10 would actually only run NINE times not 10.

Leave a Reply

Your email address will not be published. Required fields are marked *