Beginner CS students are quick to accept the concept of conditional statements — if <conditional> then do <something>. A lot of instruction about coding conditionals starts with real life examples of if-statements. That’s where I think the weak understanding begin…
1. if isLessonOnConditionals {
2. useBadExamples()
3. }
The root concept of conditionals is program flow or “identifying which lines of code happen and which don’t.” It would not surprised me to learn that many students don’t think line 1 is executed — but that’s a deeper discussion that doesn’t need to be had now — which means, in the above example there’s no clear contrast. Maybe we should be surrounding example if-statements in contextual code to have clear examples of some code that always happens and some code that conditionally happens.
0. writeAgendaOnBoard()
1. if isLessonOnConditionals {
2. useBadExamples()
3. }
4. assignHomework()
When the else block is introduced, I think it becomes even more helpful to have preceding and subsequent statements to highlight ‘always vs. condition 1 vs. condition 2.’
While introducing ‘if’s in Python to my 9th-grade Intro CS students, the above issue tripped me up, and I had to backtrack for a day. Then, as I started writing about this and thinking further about teaching if-statements, I realized that this two-letter command is very jarring. An if-statement is likely to be the first time:
- text does not start on the left edge of the page,
- the squiggly bracket key is used,
- something is being written that is supposed to be skipped, and
- not every line of code happens every time.
Add to that, conditionals are a significant advance in algorithm sophistication. A generalized algorithm that uses a conditional requires the creator to have thought through and simultaneously described all options. (The various execution paths do not need to be written in parallel, but the final algorithm holds within it a description of all possibilities.) This can be mentally trying.
Maybe I have been breazing over this very critical step and hoping students would see and write enough of them they would eventually catch on. It will be helpful to spend more time considering how I mentally process a branching point in code and how I can provide better scaffolding for students.

Leave a reply to zamanskym Cancel reply