r/visualbasic • • Oct 20 '16

Reasoning behind backwards loop

I am running some code to look through our bank and match it to our accounting, and i am using a for i=m to 1...next loop - step -1. When i change it to go forward ( step+1) it messes everything up. I've seen this before, but why?

5 Upvotes

4 comments sorted by

View all comments

2

u/Avantgardedane Oct 20 '16

I was wondering, if there was a general reasoning behind looping backwards, but i think i found it. It is because i delete rows, and when i go forward, it messes up my count :)

1

u/PostalElf VB.Net Intermediate Oct 20 '16

Exactly right! :) That's also the most common reason to use a For loop as opposed to a For-Next loop.