Again, the results should look very familiar. The for function above will light up each pin starting at 13 and counting down to 9 in sequence, turning it off before it lights the next one. You'll notice int ledPin=13 in the for statement. In this case ledPin only has meaning inside the for loop, this variable is not declared at the beginning of the program.
The basic structure of "for" is as follows:
for(initialization; condition; increment)
All for loops will have an integer variable associated with them. I chose to use ledPin as the variable name since we'll be lighting an LED. The process runs as a loop. The condition is checked, if true the code in the brackets is run and then the expression is executed. Then it checks to see if the condition is still true. It functions just like our while loop. In this loop, is ledPin greater than or equal to 9? If true the code is run and Expression are completed. For our loop, the value of ledPin will be decreased by 1 each time through, which will cause the next LED to light up.
When ledPin is decreased to 8 the condition is no longer true and the process stops. Overall, this is very similar to how we used our while loop. As we've said before, there are often many ways to complete the same task. Some of these ways will work better in certain conditions than others, but often it doesn't matter how you do it.
There is another, probably better way, to write the expression ledPin = ledPin - 1. We can use an incremental operators. In this case it would be ledPin--. ledPin-- means take one away from the value of ledPin.
So, if we let x=2, then x+=5 would set x to be 7. Again if we let x=2, then x*=5 would set x to be 10.