loops in general

raw at math.arizona.edu raw at math.arizona.edu
Tue Apr 10 14:21:55 AEST 1990


In article <1274 at proxima.UUCP> you write:
>In article <1546 at amethyst.math.arizona.edu> raw at math.arizona.edu writes:
>>
>>So lets make it easier on all.  Demand a loop {stmnt} test {stmnt} repeat
>>in ANSI C!!!!!!!!!!!!!!!!!!!!!!!!!!!
>> 
>>                        Richard Walter

First, I never said that ansi C should contain a loop repeat as above.  This
 was added by some one else.

>
>Funny, I've never used a LOOP .. EXIT construct, not even in those PASCAL

The language I was progamming had only the above loop stmt test stmt rpeat
structure to replace while{} and do {} while.  I found it much easier and
more intuitve to use, but it took practice to use effectively, just like any
other construct in any language you chose to mention.  Most other languages
offer something similar.  In C for(;;){ stmt {break on test} stmt } or
 while (true) { stmt {break on test} stmt} for instance.  But IMHO these are
misuse, yes even perversions of the intent of the language.

> Firstly, I don't like looking
>for the exit from a loop construct; secondly it allows multiple exits,
>which run counter to my structured programming orientation

There was no multiple exit from the loop construct I mentioned.  Only misuses
of for or while stmts permit multiple exits.  I also dislike this.   Looking
for the loop exit was easy.  Included was a 'formater' that indented the code.
I used it as a debugger.

> thirdly,
>as I said, it's unnecessary, at least to me;

While loops are also unnecessary as FORTRAN proves over and over again.  But
they are convenient and make code easier to understand.  My point is that the
loop construct I like is, IMHO, more convenient that whiles and do whiles.

> I have written a lot of
>code and I am not embarrassed to set a condition variable to tell me
>whether the loop should be repeated or terminated, nor is the ineffi-
>ciency (space only, for that matter) of a preliminary loop execution
>likely to cause me to lose any sleep.

Nor am I.  My sleep is continuous also.

>
>Also, I _have_ used for(;;) which my personal "util.h" defines:
>
>#define		forever		for(;;)
>
>where I don't expect the loop to terminate except when the power

IMHO,  bleech!  But a reasonable way to do it in C.
personally, I prefer

#define forever while(1)



			Richard Walter



More information about the Comp.std.c mailing list