teacher note Teacher note: “Waiting” while

Researchers have found that some students hold the following misconception: if statements “wait” for their conditional statement to become true. When that happens (at whichever point in the program), the corresponding block of code is executed.

This misconception might also appear in students’ understanding of the while loop: the loop body is executed whenever its condition becomes true.

Activity: CodeLens 1 (WaitingWhile1)

In the above example, the student might predict that the while loop will execute as soon as size is set to 0 at the end of the program, displaying the following output:

11
22
33
44

On the contrary, the while loop is never executed in the example, since size is not less than 5 at the point of evaluation of its conditional statement. The loop is never returned to even after size is set to 0.

To find out if students hold these misconceptions, show these program examples and ask them to predict the output. Alternatively, observe them as they trace through these examples by hand line-by-line. Then, have them compare their predictions to results from tracing the code using CodeLens, and, if different, ask them to try and explain why. Emphasize the sequential flow of execution through the program.

Let’s say that you showed Sam this program that simulated a thermostat of an air conditioner:

1targetTemperature = 75
2roomTemperature = 90
3while roomTemperature > targetTemperature:
4    roomTemperature = roomTemperature - 2
5
6targetTemperature = 64
7print(roomTemperature)
You have attempted of activities on this page