June 16, 2024, 06:27:53 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


FOR/NEXT Loop Problem

Started by Tony, November 21, 2008, 06:59:35 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Tony

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

Ionic Wind Support Team

Because you have an error ;)

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

Should be:

NEXT i

Ionic Wind Support Team

Tony

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.  :)