Conditionals
script {
fun example() {
if (x > 5) x = x - 5
}
}script {
fun example() {
if (y <= 10) y = y + 1 else y = 10
}
}script {
fun example() {
let z = if (x < 100) x else 100;
}
}script {
fun example() {
if (x > 5) x = x - 5
}
}script {
fun example() {
if (y <= 10) y = y + 1 else y = 10
}
}script {
fun example() {
let z = if (x < 100) x else 100;
}
}script {
fun example() {
// x and y must be u64 integers
let maximum: u64 = if (x > y) x else y;
// ERROR! branches different types
let z = if (maximum < 10) 10u8 else 100u64;
// ERROR! branches different types, as default false-branch is () not u64
if (maximum >= 10) maximum;
}
}script {
fun example() {
if (condition) true_branch // implied default: else ()
if (condition) true_branch else ()
}
}script {
fun example() {
let maximum = if (x > y) x else y;
if (maximum < 10) {
x = x + 10;
y = y + 10;
} else if (x >= 10 && y >= 10) {
x = x - 10;
y = y - 10;
}
}
}