Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uwm.edu!rpi!bu.edu!xylogics!transfer!lectroid!jjmhome!smds!rh From: rh@smds.UUCP (Richard Harter) Newsgroups: comp.lang.c Subject: Re: a style question Summary: Bad style and now you know why Message-ID: <203@smds.UUCP> Date: 1 Oct 90 10:12:01 GMT References: <7341@darkstar.ucsc.edu> <1990Sep30.050655.13212@zoo.toronto.edu> Organization: SMDS Inc., Concord, MA Lines: 44 In article <1990Sep30.050655.13212@zoo.toronto.edu>, henry@zoo.toronto.edu (Henry Spencer) writes: > In article <7341@darkstar.ucsc.edu> aryeh@cash.uucp (the over worked C something or another) 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++) ... > Most people find it more readable with a bit of space and the statement > on the next line: > for (x = 0; x != 100; x++) > ... > The cautious would also recommend `x <= 100', but in this situation that > is arguable. > I assume `x' is an integer variable, not floating-point. The original construction is bad style unless the value of x is being altered within the loop so that x==100 is the termination condition. If this is the typical loop structure the normal idiom is for (x=0;x<100;x++) {...} There is a good reason for using this idiom if you think about it. In C an array of size N has valid indices from 0 through N-1. Since many loops reference arrays it is normal for an N times loop to use the same indexing pattern so that the termination condition for a loop with increasing indices is index >=N or index