Coding Qubics in QL

Control Structures (Loops and Conditions)

Currently there are only three control structures: if, if-else and while.

General Syntax

The controlling condition has to be put into round brackets: (...), the controlled block into into braces: {...}. Even if the block consists of only a single command, you have to set braces:


if (a == 3)
    a = 8;


if (a == 3) {
    a = 8;
}

if/if-else Statement

Pretty intuitive, there is not much to say about this.


if (a < 0) {
    a = 0;
}


if (money >= 100) {
    mood = 'good';
} else {
    mood = 'bad';
}

while Loop

Guess an example is sufficient here as well:

while (x < 1000) {
    x = x*a;
    a = x+a;
}

for Loop

There is no for loop as of now but it can easily be realized with a while loop instead:

i = 0;
while (i < 10) {
    ... 

    i = i + 1;
}