Previous: , Up: Imperative Language Interpreter Usage Outline   [Index]


5.1.6 Sample Programs

The just completed interpreter may not be very able, still it can run a few programs.

The first ever:

otext("Hello, World!\n");

outputs:

Hello, World!

The first 16 Fibonacci numbers:

integer a, b, i;

a = 0;
b = 1;

ointeger(a);
obyte('\n');
ointeger(b);
obyte('\n');

i = 2;
while (i < 16) {
    integer c;

    c = a + b;

    ointeger(c);
    obyte('\n');

    a = b;
    b = c;

    i = i + 1;
}

outputs:

0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610