by mort96 · 3y ago · 0 comments
Loops would look like:
int i = 0;
loop_start:
print i;
i = i + 1;
if (i < 10) goto loop_start;
Fizzbuzz would look something like: int i = 0;
loop_start:
if (i % 5 != 0) goto not_fizzbuzz;
print "fizzbuzz";
goto done;
not_fizzbuzz:
if (i % 3 != 0) goto not_fizz;
print "fizz";
goto done;
not_fizz:
if (i % 5 != 0) goto not_buzz;
print "buzz";
goto done;
not_buzz:
print i;
done:
i += 1;
if (i < 100) goto loop_start;
Often, this wasn't just constrained to a single function; the whole program would be constructed like this, with gotos which jump back and forth across pages and pages of code. Languages wouldn't even have a call stack with subroutines (which is why "procedural" languages -- languages with procedures -- were important enough to be given a special name).At least that's my understanding of it. I haven't lived through this, and my only experience with this kind of stuff is writing assembly, where we always make use of a call stack, so even that is in practice a procedural language. If I have gotten anything wrong, please correct me.
https://github.com/Keith-S-Thompson/fizzbuzz-c/blob/master/f...
#include <stdio.h>
#include <setjmp.h>
int main(void) {
jmp_buf jb[7];
volatile int j = 0;
setjmp(jb[0]);
volatile int i = 1;
if (j == 0) setjmp(jb[1]);
if (j == 1 && i > 100) longjmp(jb[6], 0);
if (j == 1 && i % 15 == 0) longjmp(jb[4], 0);
if (j == 1 && i % 3 == 0) longjmp(jb[2], 0);
if (j == 1 && i % 5 == 0) longjmp(jb[3], 0);
if (j == 1) printf("%d\n", i);
if (j == 1) longjmp(jb[5], 0);
if (j == 0) setjmp(jb[2]);
if (j == 1) puts("Fizz");
if (j == 1) longjmp(jb[5], 0);
if (j == 0) setjmp(jb[3]);
if (j == 1) puts("Buzz");
if (j == 1) longjmp(jb[5], 0);
if (j == 0) setjmp(jb[4]);
if (j == 1) puts("FizzBuzz");
if (j == 0) setjmp(jb[5]);
i ++;
if (j == 1) longjmp(jb[1], 0);
if (j == 0) setjmp(jb[6]);
j ++;
if (j < 2) longjmp(jb[0], 0);
}OTOH early FORTRAN had procedures with arguments and results, but no recursion.
Structural or not was also not necessarily all-in. FORTRAN and BASIC both had for-loops before they had structured conditionals.
loop_test: IF (NOT loop_condition) GOTO after_loop
loop_body
GOTO loop_test
after_loop: etc...