if / else
Try it yourself →Branching based on conditions.
Syntax
if (condition) { ... } else { ... }Description
The condition is written inside parentheses; if true, the first block runs, otherwise the else block runs. else if is used for intermediate conditions.
Example
void main() {
var age = 20;
if (age >= 18) {
print("Adult");
} else {
print("Child");
}
}Expected output
Adult
When to use?
Decision making, input control.