TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: ROGER SCUDDER
from: DARIN MCBRIDE
date: 1998-04-24 13:50:00
subject: Nested loop

SA> for (count=1; count!=6; count++)
 RS> Using a test for absolute equality or inequality for the test
 RS> portion of a loop is not a good idea.  It's safer to always use
 RS> a test for "less than" or "less than or equal to" or the
 RS> flip side of "greater than" or "greater than or equal to".
Actually, testing for "absolute" equality/inequality is exactly what the C++ 
standard template library uses for its iterators.
When using non-integral types (float, double, long double), you cannot use 
absolute equality.  When using integral types (everything else), you can.  
When iterating (pointers, usually), it's often a good idea.  Sometimes it's 
the ONLY idea (when iterating through, for example, linked lists?).
 RS> It's not an idea I came up with.  It's something that was passed 
 RS> on to me by people with many years experience.  The idea is also 
 RS> backed up by countless examples in quality instructional text.
I realize this is the C_ECHO, not the C_PLUSPLUS echo, but these guys at HP 
aren't exactly newbies.  :-)
However, in this particular case, convention wins out, and count < 6 should 
be used.  :-)
---
---------------
* Origin: Tanktalus' Tower BBS (1:250/102)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.