Conditions with if and else
def absolute(value: int): int {
if (value < 0) {
return 0 - value;
} else {
return value;
};
}
def main(): int {
return absolute(-42);
}عرف مطلق(القيمة: عدد): عدد {
إذا (القيمة < 0) {
أرجع 0 - القيمة;
} وإلا {
أرجع القيمة;
};
}
عرف الرئيسية(): عدد {
أرجع مطلق(-42);
}
Run it
With the interpreter, without compiling:
./build/sultanc run examples/en/control_flow/conditions.snOr compile it to an executable:
./build/sultanc examples/en/control_flow/conditions.sn -o build/example && ./build/example