Artful Computing

Loops and branches are the most fundamental structure in programming. They give programming its algorithmic power.

Looping allows a task to be repeated again and again (this is technically called iteration) usually with some slight changes each time. Your algorithm for eating chocolates is:

  1. Pick chocolate out of box.
  2. Eat chocolate.
  3. Loop from 1, until box is empty.

I have highlighted "until box is empty" because this is the termination condition - the branch out of the loop. Loops nearly always have branches (or conditional execution) to handle conditions that make it impossible to continue with the loop. 

 

A different type of branch in the loop might be:

  1. Pick chocolate from box
  2. IF chocolate is caramels THEN return it to box.
  3. ELSE eat chocolate.
  4. Loop from 1 until box contains only caramels.

 

You need both loops and branches (iteration and conditional execution) to implement algorithms of more than trivial complexity, and that is pretty much it as far as the algorithmic part of programming goes. Oh! there are fancy ways of dressing up loops and branches, but it is just window dressing.

Most of the rest of programming is concerned with how to handle data (storing it so it can be easily found and used, moving it around and so on) and how to interact with the outside world (take instructions, write pixels to a screen etc.). This is all extremely important for creating programs big enough to do useful things in the World, and you should not underestimate the amount of thought that needs to go into organising the information flows through a program: this is where professional software engineers actually spend much of their time. But you cannot make the data do anything without the algorithms.

Breadcrumbs