Today, it's hard to see the big deal about the GOTO
statement because the "structured programming" people mostly won the debate and today's languages have sufficient control flow structures to avoid GOTO
.
Count the number of goto
s in a modern C program. Now add the number of break
, continue
, and return
statements. Furthermore, add the number of times you use if
, else
, while
, switch
or case
. That's about how many GOTO
s your program would have had if you were writing in FORTRAN or BASIC in 1968 when Dijkstra wrote his letter.
Programming languages at the time were lacking in control flow. For example, in the original Dartmouth BASIC:
IF
statements had no ELSE
. If you wanted one, you had to write:
100 IF NOT condition THEN GOTO 200
...stuff to do if condition is true...
190 GOTO 300
200 REM else
...stuff to do if condition is false...
300 REM end if
Even if your IF
statement didn't need an ELSE
, it was still limited to a single line, which usually consisted of a GOTO
.
There was no DO...LOOP
statement. For non-FOR
loops, you had to end the loop with an explicit GOTO
or IF...GOTO
back to the beginning.
There was no SELECT CASE
. You had to use ON...GOTO
.
So, you ended up with a lot of GOTO
s in your program. And you couldn't depend on the restriction of GOTO
s to within a single subroutine (because GOSUB...RETURN
was such a weak concept of subroutines), so these GOTO
s could go anywhere. Obviously, this made control flow hard to follow.
This is where the anti-GOTO
movement came from.