04-09-2010, 11:16 AM
programandala.net Wrote:In fact, the semantic of FOR is not that. For example:boriel Wrote:Thank you for the explanation. I understand. But at first sight I supposed it would work, because the index values were in range (0-255) for ubyte. You're right, that means 256 iterations, but that's the range a ubyte can hold: from 0 to 255. I supposed the compile time action of NEXT would be to check if the limit (255) had been reached, and don't loop again if so. But it seems it first increases the index. I think the current behaviour is less logical.
Code:
FOR i = 0 TO 254 STEP 2:
PRINT "HELLO"
NEXT i
The meaning for FOR sentence is: "Repeat this loop until (i + step) be GREATER THAN upper limit". Since (i + STEP) is truncated to the current type of variable i (Ubyte in this case), this condition is never satisfied. Keep in mind that FOR can be used with any STEP size (not just STEP 1). In the following version (1.2.6) the compiler might issue a Warning under these circumstances.
I suggest you to try the LOOP workaround code I put above.
Quote:I'll check what FreeBASIC does in such cases.Please, do, since I'm trying to get close to FreeBasic as much as possible (preserving most of ZX BASIC on the other side ;-))