Signed word lengths and indexes

BCS none at anon.com
Tue Jun 15 07:47:53 PDT 2010


Hello Adam,

> but this shouldn't require extra thought in the first place.

shouldn't != doesn't.

When I first saw the code, it took me about a second to go from, "backwards 
loop" to "wait, thats wrong" to "Oh, I guess that works". That's two stages 
and 750ms to long.

How would I write the loop?

foreach_reverse(uint i, 0 .. length) { ... }

or

for(uint i = length; i > 0;) { --i; ... }

or

for(int i = length; i >= 0; --i) { ... }

or

uint i = length -1;
do { ... } while(i-- > 0);

None of those at first glance seem to be wrong or work differently than they 
do.
 
-- 
... <IXOYE><





More information about the Digitalmars-d mailing list