[Gambas-user] Bug in for..next cycle with negative step?
Benoit Minisini
gambas at ...1...
Tue Sep 13 11:59:21 CEST 2005
On Monday 12 September 2005 13:44, PV wrote:
> On 10/09/2005 13:55, Laurent Carlier wrote:
> > try the following project
> >
> > regards,
>
> To further clarify the problem I found with the negative step in a
> for..next loop, I have to say that I made a little confusion.
>
> In fact, the problem showed up in my code when I used something like this
>
> DIM i as Byte
>
> FOR i = 10 TO 1 STEP -1
> [do something]
> NEXT
>
> However, I posted a message to the ML stating incorrectly that the variable
> 'i' was declared as Integer, but instead with an Integer variable
> everything seems to work just fine.
>
> So the bottom line is that with a Byte variable in a for..next loop with a
> negative step, my code still doesn't work properly.
>
> Sorry for the (possible) confusion :)
> Piero
>
*Now* I understand :-)
This is a bug... Or a feature, depends what your point of view is :-)
Byte is unsigned, so I think the interpreter casts the (-1) step to the
datatype of the loop variable, so it becomes 255!
I will try to fix that... Don't use Byte loop variable in the meantime :-)
Regards,
--
Benoit Minisini
mailto:gambas at ...1...
More information about the User
mailing list