for loops
They allow a programmer to complete a block of instructions a finite number of times. If you wanted to print Hello World 5 times, you could:
print "Hello World"
print "Hello World"
print "Hello World"
print "Hello World"
print "Hello World"
OR you could:
for i = 1 to 5
print "Hello World"
next i
i is being used as a counter variable in this case. i will start at 1 and print Hello World. next i will increment i by 1, in this case, and then the loop will print Hello World again. The for i = 1 to 5 part of the loop does the actual comparison and will check to see that i is less than or equal to 5. When next i is called and i gets incremented to 6 the loop will be finished and the program will continue with the instruction that follows the next i statement.
In Ro-Bot-X’s example:
Tilt_right_15:
for i = 145 to 130 step -5
servo 7, i
pause 20
next i
return
The for loop counts backwards from 145 to 130 in 5 step decrements. Everything between the for and next commands will be executed as many times as is allowed by the loop, in this case 4 times. Because, i will start at 145 and the loop will execute. next i will be called and i will then be decremented by 5 (step -5) and will be 140 everything inside the loop will occur. i - 5 = 135 and the loop will run again. next i, i - 5 = 130 and the loop happens once again. next i, i - 5 = 125 which is less than 130, the loop exits and the next command is return.
I hope this helps.