The Trick Of The Mind - The Goto Fixed!
Written by Mike James   
Wednesday, 24 December 2025
Article Index
The Trick Of The Mind - The Goto Fixed!
All You Need
The Goto Can Be Tamed!
Turing Completeness Revisited

We all know about the problems with the goto instruction, but after we learned it was harmful what exactly did we do about it? This is an extract from my book Trick of the Mind, which explores what it is to be a programmer.

The Trick Of The Mind - Programming & ComputationalThought

Buy Now From Amazon

Trick360

Chapter List

  1. The Trick Of The Mind

  2. Little Languages
       Extract: Little Languages Arithmetic
      
    Extract: Regular Little Language

  3. Big Languages Are Turing Complete

  4. The Strange Incident of The Goto Considered Harmful
       Extract: The Goto Considered Harmful
       Exract: The Goto Fixed! ***NEW!!

  5. On Being Variable  

  6. Representation

  7. The Loop Zoo
       Extract The Loop Zoo
      
    Extract Advanced Loops

  8. Modules, Subroutines, Procedures and Functions
       Extract Modular Programming

  9. Top-Down Programming 

  10. Algorithms
       Extract: Binary Search 
       Extract: Recursion

  11. The Scientific Method As Debugging 

  12. The Object Of It All
       Extract Why Objects 
       Extract The Benefit Of Objects 

<ASIN:B09MDL5J1S>

Structured Programming

So what is this magic method that makes the Goto so unnecessarily evil? The answer takes us back to the statements in earlier chapters about the three atoms of any list of instructions – default, conditional and loop. What Dijkstra realized was that these really were all you needed and they could be written very concisely.

The default flow of control needs nothing extra, you simply write one instruction after another:

instruction
instruction
instruction
. . .

The conditional can be expressed as the almost English:

If condition Then instruction

The instruction is only obeyed if the condition is true. For example:

If it is raining Then pick up an umbrella

If the condition is true, i.e. it is raining, then you pick up an umbrella. If the condition is not true then the picking up of the umbrella instruction is skipped. Notice that this isn’t very different from the Goto form of conditional, but also notice that there isn’t a Goto in sight. Instead of jumping to some other part of the program you simply write the instruction you want to happen after the Then – no jumps involved.

If you are worried about the fact that this only allows you to conditionally obey a single instruction then it is worth introducing the idea of a compound instruction. The default flow of control, one instruction after another, can be viewed as just one big instruction. So we can introduce some method of grouping instructions together to form a compound instruction that can be treated as if it was a single instruction.

Modern languages tend to use curly brackets {} to group instructions, but this isn’t universal. Logo, for example, uses straight brackets []. So a list of instructions in brackets of some type are generally obeyed one after the other and are treated as if they were a single “compound” instruction. For example:

If condition Then {instruction1 instruction2 …}

is an example of a conditional with a compound instruction.

Python is a little different from most current computer languages in that it doesn’t group instructions using some kind of bracket. It groups instructions by indent level. All instructions at the same indent level are considered to be a compound instruction. For example:

If condition Then
	instruction1
	instruction2
	...

It is argued that not using curly brackets looks less intimidating and the indent makes it easier to see where the If ends. 



Last Updated ( Wednesday, 24 December 2025 )