S3U
All video lessons

Science / Grades 3-6

Programming basics: choose a branch

Use an IF/ELSE flowchart and test the exact boundary of a condition.

Next: your worksheet

Programming Basics: Choose One Branch

Continue to worksheet
Not started 0s active

Checking sign-in...

Read the transcript

A program can choose a path

Programs can choose what to do by checking a condition. A condition is a question with a true or false answer. Our example asks whether points is at least five. That answer selects one of two paths through the drawing.

Read the comparison carefully

The comparison symbol means greater than or equal to. We can read it as at least five. Six meets that rule, and so does five itself. Four does not. The equal part is small on the page but important to the answer.

Follow the true path

In our pseudocode, if points is at least five, the program shows the word ready. This is the true branch. Start at the condition and follow the arrow labeled true. It leads to one display action, not to both actions.

Follow the other path

If the condition is false, the program shows practice instead. That is the else branch. With four points, follow the false arrow. The program has not become moody; it is following the rule we wrote for that value.

Pause at the boundary

Pause and predict what appears when points is exactly five. This value sits right on the boundary between the two outcomes. Do not guess from the size of the number. Read every part of the comparison, including the equal sign.

Equality belongs on this side

Five is equal to five, so greater than or equal to is true. The program shows ready. If we had written only greater than five, this same input would take the other path. Testing the boundary helps reveal that kind of mistake.

A branch can remain unused

Fun fact: a program can contain a branch that a particular run never uses. In this if and else example, only one branch runs for each check. Trying only large point values would leave the practice branch untested. Different inputs help explore different paths.

Check both sides of the rule

Trace four, five, and eight points before moving on. For each value, say whether the condition is true and which word appears. Then continue to the worksheet. The words are part of a fictional example, not a rule that changes your actual learning grade.