A for loop is a counter driven loop, the syntax is for(
var and starting value;
condition to loop while true;
increment) {
commands to be executed }
So for instance,
NPC Code:
for (i = 0; i < 10; i++) {
playerx+=.5;
sleep .05;
}
will move the player 5 spaces to the right (.5 spaces, 10 times)
But don't use it like that, the best time to use it (In my opinion) is with arrays:
Say I've got a 5 element array, and I want to set each element to whereever it is in the array, + 1, so that the array will be {1, 2, 3, 4, 5} (the first element's index in an array is 0, remember) I would do this:
NPC Code:
for (i = 0; i < 5; i++) {
myarray[i] = i + 1;
}
Get it?