[LC++]int versus unsigned int
Carlo Wood
carlo at alinoe.com
Fri Sep 28 11:08:08 UTC 2001
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>
More information about the tuxCPProgramming
mailing list