Why do FOR/NEXT variables end up +1 more?
#5
(08-24-2023, 01:02 PM)mnrvovrfc Wrote: BASIC always behaved this way about FOR... NEXT. Since Dartmouth. Many programs depend on this "quirk".

This could cause problems with an _UNSIGNED variable used like this:
Code: (Select All)
DIM u AS _UNSIGNED INTEGER
FOR u = 10 TO 0 STEP -1
PRINT u
NEXT

Expect "u" to be -1? Read the code again. Or if it were possible in QuickBASIC to compile in debug mode it would return a runtime error. This is something that never occurred to me while using QuickBASIC or QBasic. (scratch head)

Now I wasn't expecting that ... u ends up with a value of 65535, the max value.  Interesting.

EDIT: u ends up as -1 in QBJS however.

- Dav

Find my programs here in Dav's QB64 Corner
Reply


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



Users browsing this thread: 4 Guest(s)