Why do FOR/NEXT variables end up +1 more?
#1
I vaguely remember something about this at the old .com forum, but I forget the reason, so I thought I'd just ask about it here.

Why are variable used with FOR/NEXT +1 more at the end?  I was doing a count using a FOR/NEXT variable and couldn't figure out why afterwards the variable end up +1 number higher when over. 

In this example, the FOR/NEXT prints all 10 t's, but when printing the last t value over, it's at 11, and the FOR/NEXT never went to 11.  Why is that?

- Dav

Code: (Select All)

'print 10 t's

For t = 1 To 10 'stop t at 10
    Print t
Next

'so t is 10...but...

Print
Print
Print t 'this show 11 now?

Find my programs here in Dav's QB64 Corner
Reply


Messages In This Thread
Why do FOR/NEXT variables end up +1 more? - by Dav - 08-24-2023, 12:36 PM



Users browsing this thread: 2 Guest(s)