Note that you will have to reset A every itteration, or else once it gets to r1, it the while loop will only execute once after that. You could also decide to set A to r1, and decrement A instead of incrementing it, and use an End!IF A, which would make it slightly faster I believe.