Creating a For Loop

In while loop, we always want to set up the index, check the condition, and increment the index. This next loop only need one statement to write all that requirement. It's called For Loop.

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

As you can see, we do not need increment inside our loop, because it's already defined. We have the same three pieces that we need in while loop, all inside the parentheses.

results matching ""

    No results matching ""