Alderson Loop - Computerphile

The Oldest and Loopiest Program Ever Written

It's a well-known anecdote in the programming community that caused it to be nameless was that the programmer, Alderson, created a dialog box in Microsoft Access that had code which, if you clicked OK, would make it disappear but it didn't have an OK button so you could never click OK so you couldn't get rid of the dialog box and so on. So it's an infinite loop where the programmers put code in that should make it exit but for some reason this code can't exit in the current way it's running. I guess you could get it for example if someone is checking for a key on the numeric keypad to be pressed but you're running on a laptop which doesn't have a numeric keypad so you can't press that key at all or something.

So yeah, that's what the oldest and loopiest program ever written is. Can we write something that does this? I mean, is it straightforward? Well, let's give it a go, let's find a computer where we can quickly write some program so we're going to implement a program with a sort of example of what might cause an oldest and loop. Let me just switch into BBC Basic so I can knock something up relatively quickly. So let's start by creating a very simple for loop which clears off the initial votes.

I'm having to remember my BBC Basic, it's been about 30 years since I last coded it in anger but we'll get in there I've got to make sure I get this right so I get the right sort of loop condition in there. Will this be on GitHub? If I can figure out how to get it over the Echonet onto a machine I can upload it over the Ethernet on to GitHub, yes if anyone's got a GitHub client for Risk Offs please let me know.

So we've got a program here which enables us to vote for our favorite computer file presenter um and we've got three options and if we run the program we've got three options we can vote for Dave Railsford and I think quite a few people like Dave so we'll give him a few votes. We can vote for me, but we can also press zero to see the vote graphics.

If I press zero oh I'm stuck in this loop it's not recognizing that as an exit condition then we can still vote we're still at the point oh someone's voted for my oh it doesn't even let you vote for Mike might be a bit of favoritism in the voting his system here it might be rigged but we can't get out of it unless we hit escape to kill the program.

Now why is this happening? Well if we look at our code and let's go into a mode where we can see a bit more on screen at once, we've got the code here so we're printing out the display at the top which is the sort of who do we want to vote for and instructions then we print out the prompt press the key to vote. We read in the key using the GET command in BBC Basic.

We then print it out and then we then loop until we've got a valid value i one that's greater than zero and one that's less than three then we set the votes in the vote array converting it from ASCII to an integer offset into our vote that we created there and increment it by one so we do this until we get the key code that represents the letter zero.

We do have an exit condition for this loop because we're saying repeat this the whole of this until the key code that's pressed which we've got in the variable a percent is equal to the ASCII code for zero. But we also have this loop here between lines 160 and 200 that check that the key that's been pressed is one of the valid options.

What we're trying to do here is make sure we've got a valid option before we try and update the values for the votes otherwise we'd crash the program or at least get an error message from the BBC interpreter. Eight percent has to be greater than the ASCII code for zero and less than the ASCII code for three this bit of the code means that this exit condition can never be reached because it says that the ASCII code has to be greater than zero and so if to end that loop has to be greater than zero, it cannot be equal to zero at this point.

So we've effectively created a program with a very simple oldest and loopiest program.

"WEBVTTKind: captionsLanguage: eni wanted to just ask about this loop that i've heard a bit about the olderson loop okay what is it well that's a good question so i and fortunately you emailed me and asked me about this beforehand and i thought what on earth is that so i went and did some digging i first of all went and well i stole dave browser's copy of the uh new hacker's dictionary although this one doesn't actually have anything that might tell us what it is we've got alpha particles all elbows i've not come across that before that's probably worth a computer file at some point and then it's aliasing so we don't seem to have anything on older sun loops there so i sort of did a bit more digging and fortunately eric raymond who wrote that has a version of it the jargon file on his website which does cover the older sun loop so i can explain a bit about what it is and where it comes from a loop in computer software basically is trying to do the same code multiple times until some condition is met or while some condition is true you can write it either way you can say repeat this until this condition is met or while this condition is true do these operations and there's various reasons why you do that um you can also set that so that it happens an infinite number of times i.e it keeps looping and looping and looping and looping and looping and looping and are we in the halting problem world here um not really because you may want it to loop forever so for example if you write a network server what you'll probably do at some point is say loot forever answering connections from the network and then you'll just kill the process if you wanted to stop you don't particularly want your there to be some condition that can be reached that will kill a network server a web server because someone might force that condition to happen but the oldest in loop is a variation on the infinite loop and it sort of combines both loops infinite loops but also a bug in the code so as we said we can write infinite loops that we want to happen but the alderson loop is a specific type of infinite loop where if you look at the source code for the program then it's obvious that the programmer didn't intend this to be an infinite loop there is some part of the source code for the program that would stop the loop in some circumstances but due to the way the rest of the program was implemented it's not possible for that exit condition to ever be reached so while there is a way out of the loop there's no way for the program to ever reach that point of the code because of other things in the program the classic example apocryphally that caused it to be nameless was that the programmer name of alderson created a dialog box in microsoft access that had code that if you clicked ok would make it disappear but it didn't have an okay button so you could never click okay so you couldn't get rid of the dialog box and so on so it's a it's an infinite loop where the programmers put code in that should make it exit but for some reason this code can't exit in the current way it's running i guess you could get it for example if someone is checking for a key on the numeric keypad to be pressed but you're running on a laptop which doesn't have a numeric keypad so you can't press that key at all or something so yeah that's what the oldest and loop is can we write something that does this i mean is it straightforward is that um yeah i mean you basically you could write code that um i mean let's give it i mean let's give it a go let's find a computer where we can quickly write some program so we're going to implement a program with a sort of example of what might cause an oldest and loop so let me just switch into bbc basic so i can knock something up relatively quickly so let's just start going into mode 12. what we're going to do is we're going to write a program that enables people to vote on their favorite well let's go for their favorite computer file um presenter and then eventually you'll be able to press another key to go and see what the results of that would be we'll start by creating a very simple for loop which clears off the initial votes i'm having to remember my bbc basic it's been about 30 years since i last coded it in anger but we'll get in there i've got to make sure i get this right so i get the right sort of loop condition in there will this be on github um if i can figure out how to get it over the echonet onto a machine i can upload it over the ethernet on to github yes if anyone's got a github client for risk offs please let me know so we've got a program here which enables us to vote for our favorite computer file presenter um and we've got three options and if we run the program we've got three options we can vote for dave railsford and i think quite a few people like dave so we'll give him a few votes we can vote for me and we can vote for mike pound but we can also press zero to see the vote graphics and if i press zero oh i'm stuck in this loop it's not recognizing that as an exit condition then we can still vote we're still at the point oh someone's voted for my oh it doesn't even let you vote for mike might be a bit of favoritism in the voting his system here it might be rigged but we can't get out of it unless we hit escape to kill the program now why is this happening well if we look at our code and let's go into a mode where we can see a bit more on screen at once we've got the code here so we're printing out the display at the top which is the sort of who do we want to vote for and instructions then we print out the prompt press the key to vote we read in the key using the get command in bbc basic we then print it out and then we then loop until we've got a valid value i one that's greater than zero and one that's less than three then we set the votes in the vote array converting it from ascii to an integer offset into our vote that we created there and increment it by one so we do this until we get the key code that represents the letter zero we do have an exit condition for this loop because we're saying repeat this the whole of this until the key code that's pressed which we've got in the variable a percent is equal to the ascii code for zero but we also have this loop here between lines 160 and 200 that check that the key that's been pressed is one of the valid options what we're trying to do here is make sure we've got a valid option before we try and update the values for the votes otherwise we'd crash the program or at least get an error message from the basic interpreter eight percent has to be greater than the ascii code for zero and less than the ascii code for three this bit of the code means that this exit condition can never be reached because it says that the ascii code has to be greater than zero and so if to end that loop has to be greater than zero it cannot be equal to zero at this point so we've effectively created a program with a very simple olderson loop and a little bug which means no one can vote for mike bagley all righti wanted to just ask about this loop that i've heard a bit about the olderson loop okay what is it well that's a good question so i and fortunately you emailed me and asked me about this beforehand and i thought what on earth is that so i went and did some digging i first of all went and well i stole dave browser's copy of the uh new hacker's dictionary although this one doesn't actually have anything that might tell us what it is we've got alpha particles all elbows i've not come across that before that's probably worth a computer file at some point and then it's aliasing so we don't seem to have anything on older sun loops there so i sort of did a bit more digging and fortunately eric raymond who wrote that has a version of it the jargon file on his website which does cover the older sun loop so i can explain a bit about what it is and where it comes from a loop in computer software basically is trying to do the same code multiple times until some condition is met or while some condition is true you can write it either way you can say repeat this until this condition is met or while this condition is true do these operations and there's various reasons why you do that um you can also set that so that it happens an infinite number of times i.e it keeps looping and looping and looping and looping and looping and looping and are we in the halting problem world here um not really because you may want it to loop forever so for example if you write a network server what you'll probably do at some point is say loot forever answering connections from the network and then you'll just kill the process if you wanted to stop you don't particularly want your there to be some condition that can be reached that will kill a network server a web server because someone might force that condition to happen but the oldest in loop is a variation on the infinite loop and it sort of combines both loops infinite loops but also a bug in the code so as we said we can write infinite loops that we want to happen but the alderson loop is a specific type of infinite loop where if you look at the source code for the program then it's obvious that the programmer didn't intend this to be an infinite loop there is some part of the source code for the program that would stop the loop in some circumstances but due to the way the rest of the program was implemented it's not possible for that exit condition to ever be reached so while there is a way out of the loop there's no way for the program to ever reach that point of the code because of other things in the program the classic example apocryphally that caused it to be nameless was that the programmer name of alderson created a dialog box in microsoft access that had code that if you clicked ok would make it disappear but it didn't have an okay button so you could never click okay so you couldn't get rid of the dialog box and so on so it's a it's an infinite loop where the programmers put code in that should make it exit but for some reason this code can't exit in the current way it's running i guess you could get it for example if someone is checking for a key on the numeric keypad to be pressed but you're running on a laptop which doesn't have a numeric keypad so you can't press that key at all or something so yeah that's what the oldest and loop is can we write something that does this i mean is it straightforward is that um yeah i mean you basically you could write code that um i mean let's give it i mean let's give it a go let's find a computer where we can quickly write some program so we're going to implement a program with a sort of example of what might cause an oldest and loop so let me just switch into bbc basic so i can knock something up relatively quickly so let's just start going into mode 12. what we're going to do is we're going to write a program that enables people to vote on their favorite well let's go for their favorite computer file um presenter and then eventually you'll be able to press another key to go and see what the results of that would be we'll start by creating a very simple for loop which clears off the initial votes i'm having to remember my bbc basic it's been about 30 years since i last coded it in anger but we'll get in there i've got to make sure i get this right so i get the right sort of loop condition in there will this be on github um if i can figure out how to get it over the echonet onto a machine i can upload it over the ethernet on to github yes if anyone's got a github client for risk offs please let me know so we've got a program here which enables us to vote for our favorite computer file presenter um and we've got three options and if we run the program we've got three options we can vote for dave railsford and i think quite a few people like dave so we'll give him a few votes we can vote for me and we can vote for mike pound but we can also press zero to see the vote graphics and if i press zero oh i'm stuck in this loop it's not recognizing that as an exit condition then we can still vote we're still at the point oh someone's voted for my oh it doesn't even let you vote for mike might be a bit of favoritism in the voting his system here it might be rigged but we can't get out of it unless we hit escape to kill the program now why is this happening well if we look at our code and let's go into a mode where we can see a bit more on screen at once we've got the code here so we're printing out the display at the top which is the sort of who do we want to vote for and instructions then we print out the prompt press the key to vote we read in the key using the get command in bbc basic we then print it out and then we then loop until we've got a valid value i one that's greater than zero and one that's less than three then we set the votes in the vote array converting it from ascii to an integer offset into our vote that we created there and increment it by one so we do this until we get the key code that represents the letter zero we do have an exit condition for this loop because we're saying repeat this the whole of this until the key code that's pressed which we've got in the variable a percent is equal to the ascii code for zero but we also have this loop here between lines 160 and 200 that check that the key that's been pressed is one of the valid options what we're trying to do here is make sure we've got a valid option before we try and update the values for the votes otherwise we'd crash the program or at least get an error message from the basic interpreter eight percent has to be greater than the ascii code for zero and less than the ascii code for three this bit of the code means that this exit condition can never be reached because it says that the ascii code has to be greater than zero and so if to end that loop has to be greater than zero it cannot be equal to zero at this point so we've effectively created a program with a very simple olderson loop and a little bug which means no one can vote for mike bagley all right\n"