Review
Review how a condition selects a branch, how a loop visits a sequence, how total and count change, and why repetition stops.
From a Question to One Branch
A comparison asks a true-or-false question. Its result is a boolean value,
True or False. Assignment uses =, while equality comparison uses ==.
An if/elif/else chain checks conditions from top to bottom and runs the
first matching branch. Exactly one branch in the chain runs. Boundary values
belong to the branch whose comparison includes equality.
and requires both questions to be true. or requires at least one. not
reverses a boolean result. A chained comparison such as
18 <= reading < 22 expresses one interval without repeating the name.
From Separate Names to Repetition
A list places the readings in one ordered sequence:
readings = [18, 21, 20, 23]
len(readings) reports four. In this chapter, the list supplies values to a
loop; indexing, mutation, slicing, and copying wait until Chapter 5.
A for loop visits each value in a sequence. range(stop) instead supplies
integers from zero up to, but not including, the stop value. Expand a short
range by hand when its boundary is uncertain.
State Before, During, and After a Loop
A running summary begins before repetition:
Each iteration combines the earlier state with the current reading. The explicit updates
make that flow visible. += is the shorter form used after the update is
understood. Initialization inside the loop would erase earlier work.
A while loop checks a changing condition before every iteration. A complete
trace records the starting state, condition result, body, update, and final
false check. If the body does not move the condition toward false, the loop may
not finish. Zero-, one-, and boundary-iteration cases reveal many mistakes.
Processed, Skipped, and Unvisited Values
None can mark an unavailable reading. Check reading is None before
numerical comparison or arithmetic; absence is not zero.
continue ends only the current iteration, so later values remain available.
break ends the nearest loop, so later values remain unvisited. Use an
ordinary condition when it states the policy more clearly. A trustworthy
summary accounts for values in all three states: processed, skipped, and
unvisited.
The complete chapter path is:
condition → selected branch → sequence → repeated action
→ updated state → stopping decision