[Gambas-devel] gb3: recent revision regarding FOR...NEXT loops and counter variables
Benoît Minisini
gambas at ...1...
Thu Sep 1 23:01:55 CEST 2011
> On 09/01/2011 07:35 AM, Benoît Minisini wrote:
> >> Holy shit something is seriously wrong with a recent commit. All my
> >> loops are going infinitely by wrapping around to negative values. Guess
> >> no one's using the most recent build or they'd have noticed. Try
> >> something like this in a module with no other code:
> >>
> >> ' Gambas module file
> >>
> >> Public Sub Main()
> >>
> >> Dim Counter As Short
> >>
> >> For Counter = 0 To 32767
> >>
> >> Print Counter
> >>
> >> Next
> >>
> >> End
> >
> > There was a bug fix in loop management.
> >
> > And your loop must loop indefinitely, because a short value wraps to
> > -32768 after 32767, so the limit is never passed.
> >
> > The solution is not using a Short as loop variable.
>
> I understand what it's doing now. The "final" Next overflows the
> counter, making the loop infinite. While that makes sense, something
> doesn't quite smell right. I presume this behavior goes for any integer
> type, such as Byte, Integer, Long, etc.?
Of course.
--
Benoît Minisini
More information about the Devel
mailing list