|
Post by adolfomartinfuentes on Oct 7, 2023 6:20:43 GMT -5
Hello everyone,
as part of a larger program I am experiencing problems with a simple for-next loop,
-- sample code begins --
010 FOR X = 0 TO 1 STEP 0.1 020 PRINT X 030 NEXT X 040 END
-- sample code ends --
as the variable X is taking only the limiting integer values 0 and 1, instead of the values 0, 0.1, 0.2, ..., 0.9, 1, as one would expect.
The issue is experienced in the free version of RunBASIC v1.0.1b2.44 for Mac OS X, as well as in the current online version.
Could anybody be of help?
Thank you very much!
Sincerely,
Adolfo
|
|
|
Post by StefanPendl on Oct 7, 2023 23:11:35 GMT -5
FOR..NEXT is only accepting integers, this is the case for many ANSI BASIC versions. To overcome this limitation use the following:
FOR I = 0 TO 10 PRINT I/10 NEXT
Hope this helps.
|
|
|
Post by adolfomartinfuentes on Oct 10, 2023 3:09:17 GMT -5
Hello Stefan,
thank you very much for your answer.
The reason for my post is that I have been working on the contents of a BASIC course during the last days and I did not want to give the students such an example.
I have been reading the ANSI BASIC standards during the last days and in the standard for Minimal BASIC it is stated that the normal behaviour should be to set the STEP to 1 when no value is given, but constructions such as FOR X = 0 TO 1 STEP 0.1 should work within the limits of machine arithmetic.
Wish you a nice day!
Sincerely,
Adolfo
|
|