[mw-devel] CVS Update at silver.sucs.org: marvin

steve at nexusuk.org steve at nexusuk.org
Mon Mar 8 13:31:43 GMT 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
Comment: Public key available at http://www.nexusuk.org/pubkey.txt

iD8DBQFATHXB5zUOsIV3bqERAgEAAKCkkd/jmKimOmfwL7d0gE5ErswEPQCfTSxH
gWgl2XGkJWERLDvNmcgRKew=
=7it8
-----END PGP SIGNATURE-----



More information about the mw-devel mailing list