Have students trace loops with break statements to reinforce the behavior of break because tracing is a powerful and straight-forward exercise.

  • Activity:
    • Create code that accomplishes something but uses breaks sloppily.
    • Students then trace this code in groups.
    • Discuss why break is a powerful but dangerous tool as a class.
    • Next, students convert the messy break code to easier-to-follow code with for or while loops.
    • Have students modify this code to add additional functionality.
    • Lastly, discuss how hard it would have been to add this functionality to the original break code that was sloppy but still successful in completing a task.

More about this tip

External Source

Interview with Dan Leyzberg.