If anything is more fundamental to programming languages than arrays, it would be loops. You can probably count the number of programming languages that dispense with loops on the fingers of one hand.

Yet loops are problematic. Loop constructs are hard to design, no two languages quite agree on what loops should look like and how they should behave. Programmers, too, find loops hard to get right. Non terminating loops, loops that loop one iteration too many or one too few and loops that introduce performance problems abound in programs. Needless to say, loops are bad news for automated program verification systems.

Of all the loop constructs out there, the one that seems the most enduring is the “while condition do stuff loop”. In the evolution of programming languages, this construct is strongly preserved so it must be extremely useful. Yet this construct is hardly intuitive. Many programming novices fundamentally misunderstand its sequential nature. It takes effort to understand that “stuff” does not just happen while “condition” is true, but that control has to reach the start of the loop, test the condition, conditionally enter the loop, perform one iteration, go back to the start of the loop, and so on.

The imperative nature of loops is particularly troublesome when you are trying to compile programs to run efficiently on parallel machines. Loops are where all the action is, but to before you can parallelize the loop, you need to know rather a lot about what goes on inside the body of the loop.

All this makes we wonder if the time has come to end loops in programming languages. Instead of providing a way to operate on the elements of a collection, one element at a time, the programming languages of the future should embrace constructs that manipulate entire collections in a way that completely hides the control flow.

There are many ways to think about “post loop programming”. My personal favorite is spread sheets. You don’t see too many loops in spreadsheets, yet people create amazingly powerful applications with spreadsheets.

 I can hardly wait to see if the next champion programming language manages to put an end to loops.