DECLARE terminating_condition BOOLEAN := FALSE; BEGIN WHILE (NOT terminating_condition) LOOP do_stuff (terminating_condition); END LOOP; END;Here is a typical protest: "One of the answers is given that we could use a WHILE LOOP to emulate Repeat Until. However it is to be noted that WHILE would validate the terminating condition at the start of the loop itself, but for repeat until the loop would be executed at least once even thought the terminating condition is true. In that sense that we cannot use WHILE LOOP to exactly emulate REPEAT UNTIL." And here is a very nuanced voicing of the same concern: "While I completely agree that the choice using WHILE will always execute the body of the loop at least once, I do not agree that this is an “emulation” of “REPEAT UNTIL” since the condition is evaluated before the body of the loop is executed. This feels like a “trick” question since the statement of the question specifically mentions evaluating the condition after the loop. If the wording of the WHILE choice had said “You can instead execute the body of the loop at least once by using WHILE as follows…” then I would agree that it is a correct choice." Here is my view on this: "emulate" means to me that when you run it, it will behave in the same way as the "original" formulation. WHILE loops, in general, are not like REPEAT UNTIL, in that the expression is checked before the loop body is executed. In the choice shown above, however, it is constructed so that the body of the loop is executed (and always executed once, since terminating_condition is initialized to FALSE), and then the terminating condition is checked. It seems to me that the behavior of this usage of WHILE matches what you would get if you could use a REPEAT UNTIL formulation in PL/SQL. Was it tricky? Apparently so, though I must admit that I did not intend for it to be tricky. I do believe, however, that it (the choice as it is worded) is a correct answer to the question, as it is worded. Please offer your thoughts on this.
21 July 2010
Questions raised about 22 July quiz on "repeat until"(1236)
I have received emails from several players raising questions about the 22 July quiz. Four of the 1408 players who took the quiz noticed and reported a typo in the question itself. I asked:
A "repeat until" loop executes the loop body and then checks the control expression of the loop to see if the loop should continue executing (that is, as long as that expression evaluates to TRUE, the loop executes again). Which of the following statements about the "repeat until" loop is true for PL/SQL?The problem is that the word "TRUE" should be "FALSE." That is, my statement of the definition of a "repeat until" loop is wrong. I believe that the vast majority of you did not notice, because you knew what "repeat until" meant and so you just went right on to the answers. So, first of all, Dirk will receive an O'Reilly media ebook as a prize. Second, after consulting with those who reported the issue, I have decided to not change scores and rerank for all players. As noted above, it is my belief that virtually everyone took the quiz as was intended. If you noticed this mistake, decided it was a "trick question" and answered "all wrong" as a result, please contact me at email@example.com and your score will be adjusted. Next, a number of you complained about my scoring the following choice as correct:
PL/SQL does not offer a "repeat until" loop. You can instead emulate this behavior in a while loop as follows (assume that do_stuff is defined and called correctly, and sets the value of terminating_condition to TRUE or FALSE, never to NULL):