TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Darin McBride
from: Bill Birrell
date: 2004-04-29 03:13:00
subject: Merits

>  BB> Is that not a merit?

    No answer?

 > You've also moved the increment from the while()
 > (where we've had it all along) to a new location.

    That came out of the original:-

#include 
#include 
int main(void)
{
        char *string = "this is a string";
        printf("length is %d, stdlib is
%d\n",lenstr(string),strlen(string));
        return output(string);
}
int lenstr(char *s)
{
        int n=0;
        while(*s++) n++;
        return n;
}
int output(char *s)
{       while (*s) putc(*s++,stdout);
        return 0;
}
 > Some people call this "thinking outside the box".

    Not really - that's Jonathan Creek's game. :-) The two loops quoted
have completely different functions and ranges. The first is a simple
count, the second is a fairly standard K&R string output loop.

 > However, we were intending to compare generic for()
 > and while() loops, showing how the obvious solutions
 > weren't always so obvious.

    You were implying that a for(;;) loop is inherently clearer than a
while() loop. Without elision that is simply not true.

 > You're simply proving what
 > we've said all along: don't muck with loops without
 > really trying.

    Your preferences aside, Darin, you didn't answer the question. Pre and
post-increments behave differently, and you cannot always use just one or
the other without risking gross obfuscation.

Best Wishes,
Bill.

---
* Origin: Escan BBS (2:25/200)
SEEN-BY: 633/267 270
@PATH: 25/200 108 252/110 250/501 140/1 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

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™.