5

The easily readable structure of having an if keyword which controls execution of a following block of code is so prevalent in programming that it seems to just be part of it.

However, programming started out with machine code that was far away from the easy to understand

if condition
    do thing

What was the first time a programmer was able to use this simple and intuitive way of executing code based on a condition?

This excludes IF...GOTO statements, as that - in the sense of this question - only allows to execute a GOTO statement, opposed to arbitrary code. Also condition and code to execute are split up there and not together anymore. This is more about the "usability for programmers" perspective than about the technical ability to support this feature.

As user Raffzahn mentioned, this can be called "the first (block) structured language".

  • 1
    IF-THEN-ELSE is just the compiler helping you with the two GOTO statements. – Thorbjørn Ravn Andersen Apr 18 at 16:08
  • @ThorbjørnRavnAndersen Well... most of modern programming languages is just the compiler helping me with the low level stuff. Programming languages are not made for the computer, but for humans to read - otherwise we would still be using machine code. That's the perspective to apply here. – R. Schmitz Apr 18 at 16:14
  • 1
    How many of these very specific programming language history questions do you plan on asking? – Robert Harvey Apr 18 at 16:27
  • 1
    @R.Schmitz As every programming language compiles down to something closer to machine language (also goes for interpretation) that is trivially true. The point I was trying to make is that the abstraction level for an IF-THEN-ELSE is not very much above for IF-GOTO-GOTO (I would guess that the non-nested version could be easily implemented as assembler macros), and therefore this is a rather small stepping stone. And no, we would not use assembly code. We would probably use a modern Lisp dialect. – Thorbjørn Ravn Andersen Apr 18 at 16:51
  • 1
    if(condition) begin code; end is exactly the if(not condition) goto end_of_block; code; end_of_block: so this readability could even be achieved in assembler using appropriate macros. – lvd Apr 18 at 20:10
4

With the rather vague wording the question does leave us with several options:

  • If it's just about conditional execution of non control transfer instructions, then Freiburger Code for Zuse's Z22 of 1955 will do it.
  • If it's about conditional execution of one or more instruction then any language with conditioned control transfer (IF cond THEN label) will do it, as by negating the condition any code can be inserted between both occurences of label.
  • But if this is about block structured code, then the ALGOL Family will fit all your criteria - and the Z22 was the first machine to operate one in 1958 (and the transistorized Z23 being the first machine to be delivered with an Algol compiler by default (1961))
5

ALGOL-60 is the obvious candidate; it and its predecessor ALGOL-58 (for which I can find no code samples!) are credited with inventing the BEGIN/END block structure.

  • My first programming language ;-) – user8725 Apr 19 at 13:19
  • IAL (Algol 58) had the compound statement, but Algol 60 added the precise notion that declared identifiers were scoped to the smallest enclosing block. I believe only the latter deserves the name "block structured"; we today always imply scope rules when we use the term. Still, it's not really clear whether the OP is asking about compound statements or block structure; the focus on if statements suggests interest in compound statements. – another-dave Apr 23 at 18:18
3

Autocode had the equivalent of an if...then, but written backwards:

j1,11 ≥ n

This means "if n <= 11 then jump to label 1". FORTRAN of course had a more conventional if, but with it's own oddities:

IF N-11 10,20,30

Which means goto 10 if the result is negative (N<11), 20 if its zero (equal) and 30 if it's positive (N>11). This syntax appears to be a side-effect of a particular instruction on the IBM machine it was written on.

Update: I'm not sure either really hits without that last proviso in your statement though. But Autocode's solution is essentially the ELSE clause. That was weird...

  • I'm afraid it doesn't hit the nail on the head, in short because the only thing it can do is send you somewhere else in the source code. I admit it's quite a fine line to tread. I actually posted this on softwareengineering first, because I am interested in the "usability for programmers" perspective. Retrocomputing seems to have more hardware- and low level code experts, and i agree that it's not that much of a difference in that context. I do enjoy getting all this info though, so thank you either way! – R. Schmitz Apr 19 at 9:11
0

In my first position as a professional programmer in 1982, the small mom-and-pop software shop I worked for used MS BASIC compiler to develop a point-of-sale, inventory control, and mail merge system. The MS BASIC was extremely vanilla, and had no IF ... END IF type structure, which apparently bugged the hell out of the main programmer and co-founder of the company. So much so that he wrote a pre-processor program, which I think he called XSEL or something beginning with "X" (company was XtraSoft) that allowed us to code with IF and END IF and not have to use line numbers or worry about those messy GOTO's, and would create a line-numbered output with the necessary GOTO's (ugh) to branch out at the appropriate places. It at least made the "source" code look nice, if not executable on their own through an interpreter anymore, and required the extra step of the pre-processor before compile and link, but we grew to like it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.