[mw-devel] CVS Update at silver.sucs.org: marvin
firefury at sucs.org
firefury at sucs.org
Mon Mar 8 13:46:06 GMT 2004
Argh, sorry for that last message - I went mad and sent the wrong message
to the wrong address... try again. :)
On Mon, 8 Mar 2004, Peter Berry wrote:
> As far as I can see, that's really the purpose of the C for statement,
> i.e. so you can do for any linear structure the equivalent of 'for
> (i=0;i<n;i++)'. I don't see why this is a problem where the loop length is
> variable as long as your code is sane.
To me, a linked list traversal done like:
for (ptr = head; ptr; ptr = ptr->next) {
foo
}
is sane and very readable. However, it's Justin's project so he gets to
choose the coding style :)
> Obviously ugliness is a matter of opinion. Personally I'd rather have the
> convenience of continue than have to use goto or do everything manually
> every time.
You can use continue in a while (just make sure you increment the pointers
at the start of the loop).
Generally speaking, I use for loops to traverse linked lists but while
loops if I am inserting and teleting records from them (i.e. if I'm doing
anything that involves modifying the operands of the for loop then I don't
use for because it gets unreadable).
- --
- Steve http://www.nexusuk.org/
Servatis a periculum, servatis a maleficum - Whisper, Evanescence
More information about the mw-devel
mailing list