Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ukma!rutgers!bellcore!texbell!sugar!ficc!peter From: peter@ficc.uu.net (Peter da Silva) Newsgroups: comp.lang.c Subject: Re: comma operator: keep away? Message-ID: <3953@ficc.uu.net> Date: 24 Apr 89 13:53:51 GMT References: <19913@iuvax.cs.indiana.edu> <10092@smoke.BRL.MIL> <1104@aplcen.apl.jhu.edu> Distribution: usa Organization: Xenix Support Lines: 32 In article <1104@aplcen.apl.jhu.edu>, bink@aplcen.apl.jhu.edu (Ubben Greg) writes: > In article <2179@pur-phy> (Sho Kuwamoto) writes: > > for(i=0, p=head; p->next != NULL; i++, p=p->next) > People too often cram expressions in the for(;;) that are not related > to the loop control, just to avoid a couple of extra lines. I dispute that's the motivation in this case. But putting the i=0 and i++ in the loop you're providing extra information: that the variable 'i' is tightly bound to the loop, and may be serving as a manufactured loop index. The alternative: i = 0; for(p=head; p->next != NULL; p=p->next) { ... i++; } implies that 'i' might not be bound to the loop, and also means that you would have to special-case any 'continue' statement in the expression if it is so bound. if(gottagetouttahere) i++, continue; /* :-> */ (Yes, I know you can't do that). -- Peter da Silva, Xenix Support, Ferranti International Controls Corporation. Business: uunet.uu.net!ficc!peter, peter@ficc.uu.net, +1 713 274 5180. Personal: ...!texbell!sugar!peter, peter@sugar.hackercorp.com.