Loops

A Loop is a way of making a program repeat some actions over and over again, usually a specific number of times. The draw() function already is a loop, in fact; but you can also use a loop to do repetitions within the draw function.

the FOR loop

In a for loop, you use a variable (often called i), and give it a range of values. Each time the value of that variable changes, you repeat the block of code in the loop. Here's an example
int i; // counting for (i=1;i<10;i=i+1) { println(i); }

the for loop has three parts, separated by semicolons: for ( start value ; condition ; increment)
"i=1" means that the variable will start at 1. "i < 10" means that the loop continues while i is less than 10. "i=i+1" means that each time through the loop, we add 1 to i.

Notice that the loop above only counts from 1 to 9, not 1 to 10. When i=10, the loops ends.

Counting 1 to 10

for (i=1;i<=10;i=i+1) { println(i); }

Counting by twos

for (i=1;i<=10;i=i+2) { println(i); }

Counting backwards

for (i=10;i>0;i=i-1) { println(i); }

Using the increment operator shortcut

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