do...while vs. repeat...until (was: Errors aren't that simple)

Georg Wittig wittig at gmdzi.UUCP
Wed Mar 28 19:38:28 AEST 1990


raw at math.arizona.edu (Rich Walters) writes:

>		loop
>			{ statement }
>		{while (expr) | until (expr)}
>			{ statement }
>		repeat		

>This allows _complete_ freedom in where you check for loop termination.  You
>can check at the beginnig the end or _anywhere_ in between!!!

>I think this is the bestest ever!!!!!!

Personally, I prefer that style, too. But alas, there are situations where it
is far from optimal. Example

	for (i=0;   i<2700;   ++i,++j,--k,m=f(x)) {
		...
		if (condition1) continue;
		...
		if (condition2) continue;
		...
		if (condition14) continue;
		...
	}

Try to convert that into the general form. It won't look good and clearly
arranged.

Apart from that, I must admit that a for statement makes the control of the
loop much more clear and compact.
-- 
Georg Wittig   GMD-Z1.BI   P.O. Box 1240   D-5205 St. Augustin 1 (West Germany)
email: wittig at gmdzi.uucp   phone: (+49 2241) 14-2294
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Freedom's just another word for nothing left to lose" (Kris Kristofferson)



More information about the Comp.lang.c mailing list