Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!sq!msb From: msb@sq.UUCP Newsgroups: comp.lang.c Subject: for vs. while (was: Re: documentation standards........) Message-ID: <1987Oct25.234440.16608@sq.uucp> Date: Sun, 25-Oct-87 23:44:40 EST Article-I.D.: sq.1987Oct25.234440.16608 Posted: Sun Oct 25 23:44:40 1987 Date-Received: Tue, 27-Oct-87 05:28:45 EST Reply-To: msb@sq.UUCP (Mark Brader) Followup-To: poster Organization: SoftQuad Inc., Toronto Lines: 25 Checksum: 35554 I argued that > > for (iterations = 0; upper - lower > epsilon; iterations++) was more C-style than the corresponding while-form. Chip Salzenburg (chip@ateng.UUCP) replied: > It is _not_ true that a "C programmer" will use a "for" loop whenever > possible. For example, I consider myself a fairly experienced C > programmer, and my personal rule is that only variables involved in loop > _control_ should appear in the for statement. I would amend this to "involved WITH loop control". If "iterations" was some variable that is also being modified throughout inside the loop, then I would probably prefer the while form. But here it is a simple counter of the number of times the loop runs, which is more closely involved with loop control than with the loop body. It is a fairly fine point, until the loop body gets large enough that the iteration++ moves out of sight of the iteration=0. (Of course, depending on the use of break, one may be able to put the iteration++ at the TOP of the loop body, which is okay.) Anyway, further discussion on this should probably be by mail (so I'm putting "Followup-To: poster" in the header; override if you wish). Mark Brader "We did not try to keep writing until things got full." utzoo!sq!msb, msb@sq.com -- Ritchie