Examples

Example programs in Prog.

Table of Contents

Hello World

#!/usr/bin/prog

use io;

output << "Hello, world!\n";

Hello User

#!/usr/bin/prog

use io;

output << "What is your name? ";
input >> name as string;
output << "Hello, 'name'!\n";

FizzBuzz

#!/usr/bin/prog

use io;

for (i, 1..100)

    if (i % 3 == 0 && i % 5 == 0)
        output << "FizzBuzz\n"

    elsif (i % 3 == 0)
        output << "Fizz\n"

    elsif (i % 5 == 0)
        output << "Buzz\n"

    else
        output << "'i'\n";

Factorial

#!/usr/bin/prog

use io;

def fact(n as int) => int
    return n * fact(n - 1) unless n == 2 else return n;

output << fact(5);