[NSRCA-discussion] Chapter-12 computer science.

Duane Beck duane.e.beck at comcast.net
Tue Jul 3 22:13:12 AKDT 2007


num is incremented in the body of the loop, before cnt is incremented at 
the end of the loop (right before it checks the loop condition again). 
So, num equals 1 when cnt is incremented to 1 at the end of the loop, 
before the condition is checked a second time.  Next time through the 
loop, num is incremented to 2 before cnt increments to 2.  When cnt 
equals 256 at the loop condition check (assuming it's able to represent 
such a value), num will have already been incremented to 256 in the 
previous pass through the loop body.

In general, it's poor practice to use chars for integer math.  If you 
need a small integer, use short instead.

Martin X. Moleski, SJ wrote:
> OK, I agree that cnt is incremented to 256 if it is
> the right type to do so.
> 
> Seems to me num can only reach 255.



More information about the NSRCA-discussion mailing list