Feedback While loop only 

Forum: U Chicago, Com Sci 221 old messages, autumn 2000
Re: News Assignment #3, due 18 October (Mike O'Donnell)
Re: Question assignment 3 #3 question (Maggie Novak)
Date: 2000, Oct 17
From: Mike O'Donnell <odonnell@cs.uchicago.edu>

The solution to problem 3 must be accomplished in the highly restricted language that we have been discussing in class. The only looping construct is the while loop. I'm not sure what a do-while loop is, but if it's different from our while loop don't use it.

The unfortunate inclusion of repeat-until in Pascal has led many students of programming to try to solve problems by trying out different sorts of loop constructs in the hope that one works, instead of thinking systematically through the given control-flow problem. The pure and simple if/while/composition structure that we are studying illuminates control-flow problems in a simple and uniform way. The choice of the while construct is not arbitrary. It is the simplest form of loop that allows the possibility for 0 iterations in a clean way. It is much more elegant in general to add required iterations to a while construction than to nullify the effect of unavoidable iterations when 0 is the right number. There doesn't appear to be any mathematically more elegant way to generate all the iterative computations than our if/while/composition language, without expanding into nondeterministic programs, which is quite an additional can of worms intuitively.

The pure for loop of Pascal (which we are simulating in this problem) captures the very important and common special case where the number of iterations is computed in advance, so it makes sense as a special case. The point of our exercise is to see how it has some small but important subtleties in the ranges of values assigned to the index variable.

The very general for loop of C covers all single-exit loops in a uniform way, so it makes sense as a construct, although the form in which it is presented in C is rather opaque. Other looping constructs that I know of, particularly repeat-until, deal with very limited, and not particularly common, special cases. I think that they muddy the clarity of programming in general.



Mike O'D.


Messages

to: "While loop only"