[LC++]int versus unsigned int
Robert Wuest
rwuest at wuest.org
Fri Sep 28 12:02:08 UTC 2001
OOPS, You're right!!
What got me, I needed to include 0 (I was reversing though an array), and I did
for( cnt=13; cnt>-1; cnt-- )
blah_blah_blah;
Robert
Carlo Wood wrote:
>
> On Thu, Sep 27, 2001 at 06:55:32PM -0500, Robert Wuest wrote:
> > This one just got me the other day:
> >
> > unsigned int cnt;
> > .
> > .
> > .
> > for( cnt=13; cnt>0; cnt-- )
> > blah_blah_blah;
> >
> > An infinite loop!
>
> Seems to work fine to me. It will terminate on cnt == 0.
>
> By the way, when programming C++, you should do
>
> for(int cnt = 13; cnt > 0; --cnt)
>
> (Declare the counter inside the loop).
>
> --
> Carlo Wood <carlo at alinoe.com>
> _______________________________________________
> This is the Linux C++ Programming List
> : http://lists.linux.org.au/listinfo/tuxcpprogramming List
More information about the tuxCPProgramming
mailing list