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 steven@stevenfeuerstein.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):
  terminating_condition BOOLEAN := FALSE;
  WHILE (NOT terminating_condition)
     do_stuff (terminating_condition);
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.


  1. Maybe this type of discussion can be avoided when you clearly state that there will never be 'trick' questions in the PL/SQL challenge. It's all about technical knowledge, not about being witty or a good reader...

  2. That is an excellent objective. Of course, what one person feels is a test of knowledge can often be seen by others as a "trick." After all, I didn't think the WHILE loop choice was a trick.

  3. One person wrote to me to say: "2. Your information is not enough to answer if it is reasonable. You only said that only four person reported this but we really don't know how many people just choose the choice ( like I have almost done in the first place) and not report them. You should tell us how many people mark all answers as incorrect and if it is only few number, that's ok."

    Good point. Just 19 of 1408 players submitted an "all wrong".

  4. FWIW, I didn't consider that answer to be a trick question. It was an example of poor programming style, but the question was clearly about the *behaviour* of the loop, not how well it's been coded.

  5. When I wrote the “nuanced” description of my issues with the “WHILE” choice I did not mention that part of my concern was due to the wording “You can instead emulate this behavior in a while loop as follows” (bolded emphasis mine) which I took to indicate that the code that followed was intended to illustrate a general solution and not a specific case. My interpretation of the intent was probably affected by the fact that I’ve been reading several academic texts which tend to have very precise use of language to distinguish between abstract illustration and concrete example (this is especially true of works by authors such as C. J. Date and Donald Knuth). The mistake was mine and, as I stated in my email to Steven Feuerstein, I don’t think the question was intentionally misleading nor am I requesting a rescoring.

  6. > 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.

    Hi, Steven!

    I think about the similar behavior too, and the choice #2 (LOOP with do_stuff and following EXIT WHEN) is correct from this point of view. But the choice #4 doesn't emulate the behavior, it emulates the results.