If you read through the link Copeg supplied it answers the question. The problem isn't the for loop, it is a problem with your variables.