Skip to content

Control Flow

This content is for v0.2.1. Switch to the latest version for up-to-date documentation.

RayQuiro provides standard control flow statements for branching and looping.


var score = 85;
if (score >= 90) {
print("Grade: A");
} else if (score >= 80) {
print("Grade: B");
} else if (score >= 70) {
print("Grade: C");
} else {
print("Grade: F");
}

Parentheses around the condition are optional or standard, braces {} around the block are required.


The while loop executes its body repeatedly as long as its condition evaluates to a truthy value:

var count = 0;
while (count < 5) {
print("Iteration: " + str(count));
count = count + 1;
}

Terminates the innermost loop immediately:

var i = 0;
while (i < 100) {
if (i == 42) {
print("Found target: 42. Halting loop.");
break;
}
i = i + 1;
}

Skips the remainder of the current iteration and jumps to the next condition evaluation:

var n = 0;
while (n < 10) {
n = n + 1;
if (n % 2 == 0) {
continue;
}
print("Odd number: " + str(n));
}

var fruits = ["apple", "banana", "cherry", "date"];
var idx = 0;
while (idx < len(fruits)) {
var item = fruits[idx];
print("Fruit #" + str(idx + 1) + ": " + item);
idx = idx + 1;
}