Code: Select all
for a = 1 to 3 step .2
print a
next
Code: Select all
a = 1
while a <= 3
print a
a = a + .2
wend
Code: Select all
for a = 1 to 3 step .2
print a
next
Code: Select all
a = 1
while a <= 3
print a
a = a + .2
wend
As I said earlier, that should be an issue for the end user (programmer) to deal with, not the language developer. This problem will exist with floats no matter what you come up with as a workaround.It makes the looping unreliable! This is proven in the Commodore example. How can that not be a reason to implement them? The makers of PB aren't trying to build junk that can't be relied on to work every time - one loop or a billion loops.
Float counters used in a While-Wend loop are accessible to the programmer and can be "cleaned up" after incrementing and before testing to see if it's still in the range, but the only person who can manipulate the counter at that stage in a For-Next loop is the language developer. Anything the programmer does after "For" and before "Next" isn't going to help.As I said earlier, that should be an issue for the end user (programmer) to deal with, not the language developer. This problem will exist with floats no matter what you come up with as a workaround.
Float counters used in a While-Wend loop are accessible to the programmer and can be "cleaned up" after incrementing and before testing to see if it's still in the range, but the only person who can manipulate the counter at that stage in a For-Next loop is the language developer. Anything the programmer does after "For" and before "Next" isn't going to help.
Code: Select all
for a = 1 to 3.2 step .2
print a
if a > 3 then exit for
next
or
for a = 1 to 3.2 step .2
print a
if a > 3 then goto there
next
there:
Rubbish. Both of those code snippets were tested in QBasic and work exactly as you'd expect them to: a never exceeds 3.What you do to it beforehand doesn't affect this operation.
Execution of the exit-for-statement shall cause execution to continue at the line following the next-line of the smallest for-loop in which the exit-for-statement occurs.
Code: Select all
i.f=1.00
Repeat
i+0.2
Debug i
Until i>2.8
Yes, Chris319, you're right: It SHOULD be up to the programmer to decide if this is appropriate for their needs. So why not make it available? Most of us already know of the 'shortcomings' of floats (not just in PB, but in almost every other language too), but that doesn't mean we don't want to use them from time to time.chris319 wrote:As I said earlier, that should be an issue for the end user (programmer) to deal with, not the language developer. This problem will exist with floats no matter what you come up with as a workaround.It makes the looping unreliable! This is proven in the Commodore example. How can that not be a reason to implement them? The makers of PB aren't trying to build junk that can't be relied on to work every time - one loop or a billion loops.