Attention
PotatoOS is currently in early alpha and is not available for download. Features and APIs documented here are subject to change.
Control Flow¶
All blocks must be wrapped in curly braces ({}).
If Statements¶
Use the if keyword to create an if statement. You can also use brackets. Additionally, you can use elif and else to create branches.
// This is in Celcius
if temperature > 30 {
return "It's hot!";
}
elif (temperature < 20) {
return "It's cold!";
}
else {
return "Nice temperature!"
}
Loops¶
For Loops
To create a for loop, use the for keyword (Pretty intuitive, huh?). Then use a variable and in to iterate over a list. You don’t need brackets.
for i in [1..3] {
print(i);
}
While Loops
A while loop repeats until a condition is false. Use the while keyword and a value to create one.
var condition: bool = true;
var counter: int = 0;
while condition {
counter += 1;
print("Looping!")
if counter >= 10 {
condition = false;
# You can also use break
}
}
Functions¶
To define a function, use function. Arguments are in a comma delimited list, and you can supply defaults using or:
function main(text: str or "Hello, World!") -> void { # returns null
print(text);
}
Classes¶
Classes are created with the class keyword. If the function _init is defined, it will be called on instantiation. Create self-references using this. Use a colon (:) for inheritance.
class Human {
var name: str = "";
function _init(name: str) -> void {
this.name = name;
}
}
var john: Human = Human("John");
print(john.name); # John
class Programmer : Human {
var routine: array = [];
function _init(name: str, routine: array) -> void {
super(name); # Call _init for the parent class
this.routine = routine;
}
}
var alice: Programmer = Programmer("Alice", ["code", "sleep"]);
print(alice.name); # Alice