It is called a for loop.....
dim n,x as integer
For x - 0 to n
I hope this gives you some direction.
-note: this is not intended to be a solution, but a wire diagram of ONLY ONE example of how this could be accomplished. this is purely archaic, but is an example of programming logic!