Control Flow & Loop Tracing


Answer & solution
Answer: begin S; while not B do S end (no official key was published)
A repeat loop executes S before checking B, so S runs at least once. Execute S once explicitly, then test not B in the while guard. Whenever B remains false, execute S again; stop immediately after an iteration makes B true. Merely writing while not B do S would incorrectly permit zero executions when B starts true. This transformation preserves the sequence of evaluations of B after executions of S, including ordinary side effects in the condition. If S is a multi-statement sequence, it must be grouped as a Pascal compound statement.