Skip to content

Example Code

Maximilian Winter edited this page Apr 7, 2022 · 10 revisions

Code for calculating the first 50 fibonacci number and write them to the console.

module MainModule;

import System;
using System;

// Fibonacci Example

function FindFibonacciNumber(n)
{
    var count= 2;
    var a = 1;
    var b = 1;
    var c = 1;
    if(n == 0)
    {
        return 0;
    }
    while(count<n)
    {
        c = a + b;
        a = b;
        b = c; 
        count++;
    }

    return c;
}

for(var i = 0; i < 50; i++)
{
    PrintLine(FindFibonacciNumber(i));
}

Simple code to show the use of inheritance and access of members.

class Foo
{
    var x = 5;
}

class TestClass : Foo
{
    function TestClass(n)
    {
        x = n;
    }
}

function TestFunction(n)
{
    n.x = 10;
}

var t = new TestClass(500);
PrintLine(t.x);

var a = new TestClass(150);

PrintLine(a.x);

TestFunction(a);

PrintLine(a.x);

Clone this wiki locally