Lesson 2 of 6 · Conditions and loops
Use conditions and loops without changing the question
8 minute lesson · 3 checks along the way
Your goal for this lessonTrace selection rules and repeated operations carefully.
In this lesson 3 sections · 3 checks
Using archive links & definitions
Words with a dotted underline open a short definition right here in the lesson.
Read & understand
A condition chooses a branch
A evaluates a stated test and determines which action follows. For example, a fictional quality rule might accept a reading only when its valid flag is true and its uncertainty is below a chosen threshold. “And” requires both conditions; “or” accepts either one. The choice changes the scientific sample.
Threshold boundaries also matter. A rule saying value is greater than 5 excludes exactly 5, while greater than or equal to 5 includes it. Neither is automatically the right rule; the intended definition must decide. A boundary example makes the distinction easy to check.
Check 1 of 3
10 pointsUse the reading above. You can try again without losing points.
Read & understand
A loop repeats a defined operation
A can visit each row in a dataset, applying the same rule and updating a result. If the readings are 3, 5 and 7, the rule “greater than 5” selects only 7. The rule “at least 5” selects 5 and 7. Record the accepted count as well as the result.
A loop also needs a clear stopping condition. A fixed list ends after its last entry; an iterative calculation might stop when a stated is met or a maximum count is reached. A maximum prevents endless work but does not mean convergence was achieved.
One boundary changes the sample
Original teaching diagram. Fictional values. 3, 5, 7. Greater than 5: select 7. Inclusive boundary. At least 5. Select 5 and 7. Write the intended rule first, then test values on both sides and exactly at the boundary.
Open full-size diagram in a new tab: One boundary changes the sampleCheck 2 of 3
10 pointsUse the reading above. You can try again without losing points.
Read & understand
Separate the transformation from its bookkeeping
A helper function can express one task, such as converting units or deciding whether a record is valid. Naming the task makes the program easier to inspect, but the function still needs documented inputs and behavior. Hidden changes to shared state can make the full sequence difficult to reproduce.
For a fictional processing pipeline, count accepted and rejected rows and preserve reasons for rejection. If an updated rule doubles the accepted sample, inspect what changed before interpreting a new mean as a physical discovery. Software choices can change the evidence entering the calculation.
Check 3 of 3
10 pointsUse the reading above. You can try again without losing points.
Put it together
Your lesson progress
Each check connects to a part of the story. Complete all 3 to earn your 25-point lesson bonus.
Explore further · Optional
Go to the source
Explore the evidence behind this lesson. These optional readings and videos open in a new tab.