Computational Thinking · Computer Science

Algorithms and Loops

Following steps in order, and repeating some of them.

What's really going on

An algorithm is a set of steps that solves a problem, written clearly enough that someone else, or a computer, can follow it exactly. A recipe, a dance routine, and directions to a friend’s house are all algorithms. Many algorithms repeat some of their steps, and a loop is how you say “do this again” without writing the same steps over and over. Computers are good at loops because they can repeat steps millions of times without getting bored or making mistakes.

For educators

Background

An algorithm is a finite, unambiguous sequence of steps for solving a class of problems. Three building blocks cover most algorithms: sequence (steps in order), selection (if/else choices), and iteration (loops). Loops can repeat a set number of times (count-controlled) or until a condition changes (condition-controlled). Unplugged activities that have students write instructions for a partner to follow literally are effective at showing why precision matters and where loops save effort.

Misconceptions

  • An algorithm has to be written in code. Algorithms exist independently of any programming language; code is one way to express them.
  • The computer will figure out what I meant. Computers follow instructions exactly, so missing or ambiguous steps cause bugs.
  • A loop runs its body once and then checks if it’s done. Students often lose track of when the condition is checked and how many times the loop actually runs.