Path: utzoo!attcan!uunet!wuarchive!zaphod.mps.ohio-state.edu!usc!jarthur!nntp-server.caltech.edu!manning From: manning@nntp-server.caltech.edu (Evan Marshall Manning) Newsgroups: comp.lang.c Subject: Re: a style question Message-ID: <1990Sep30.220839.20183@nntp-server.caltech.edu> Date: 30 Sep 90 22:08:39 GMT References: <7341@darkstar.ucsc.edu> <8660@ncar.ucar.edu> Organization: California Institute of Technology, Pasadena Lines: 37 steve@groucho.ucar.edu (Steve Emmerson) writes: >>Since I going to be doing my first team effort I want to know if this is bad >>style: >> for(x=0;x!=100;x++) ... >It's OK, though some improvements could be made. Old-timers would >ususally write "x < 100" rather than "x != 100" as it expresses the >sense of direction (incrementation) slightly better, and they're more >used to seeing it that way. >A slightly more important improvement would be to use a symbolic >variable or constant for the, otherwise, non-obvious "100" value. >Something like > # define NUM_ELEMENTS 100 > for (x = 0; x < NUM_ELEMENTS; x++) ... >Note also the use of additional whitespace. Well, if the issue really is style... Don't ever use single-character variable names. I use 'ix' for loop index variables for which I can come up with no better name, but this happens rarely. If you're looping ove 'x' then 'x' means something more to you than just 'x' when you're writing the code. But it may not be immediately obvious later. There's bound to be a more useful name for NUM_ELEMENTS too. *************************************************************************** Your eyes are weary from staring at the CRT for so | Evan M. Manning long. You feel sleepy. Notice how restful it is | is to watch the cursor blink. Close your eyes. The |manning@gap.cco.caltech.edu opinions stated above are yours. You cannot | manning@mars.jpl.nasa.gov imagine why you ever felt otherwise. | gleeper@tybalt.caltech.edu