IonicWind Software

IWBasic => General Questions => Topic started by: Tony on November 21, 2008, 06:59:35 PM

Title: FOR/NEXT Loop Problem
Post by: Tony on November 21, 2008, 06:59:35 PM
There seems to be an issue with using FOR/NEXT loops. I discovered it while rewriting my card game and while working on another app. When I use a FOR loop it doesn't work properly as illustrated in the code below. On my machine it gets stuck in a loop, when it should only go through it 10 times. This is related to a bigger issue of variables becoming corrupt. If I change the code below to use a WHILE/WEND it works as it should. I'm using version 1.670 of EB on Vista Home.

$MAIN

AUTODEFINE "OFF"

DEF Count,i:INT

OPENCONSOLE

Test()

PRINT Count

DO:UNTIL INKEY$ <> ""

CLOSECONSOLE

SUB Test

Count=10

FOR i = 1 TO Count
PRINT "Here"
NEXT Count

ENDSUB
Title: Re: FOR/NEXT Loop Problem
Post by: Ionic Wind Support Team on November 21, 2008, 07:10:04 PM
Because you have an error ;)

FOR i = 1 TO Count
      PRINT "Here"      
NEXT Count

Should be:

NEXT i

Title: Re: FOR/NEXT Loop Problem
Post by: Tony on November 21, 2008, 07:15:24 PM
Oops! Sorry about that Paul. That's what I get for not programming in years and then going back and looking at 3000 lines of code.

Thanks for pointing out the error of my ways.  :)