Control Flow

Conditionals and loops for program flow.

If-Else

var score = 85;

if (score >= 90) {
    print("Grade A");
} else if (score >= 70) {
    print("Grade B");
} else {
    print("Grade C");
}

While Loop

var i = 0;
while (i < 5) {
    print(i);
    i = i + 1;
}
// 0, 1, 2, 3, 4

For Loop

for (var i = 0; i < 5; i = i + 1) {
    print(i);
}
// 0, 1, 2, 3, 4

Foreach Loop

var items = ["apple", "banana", "cherry"];

for (var item : items) {
    print(item);
}
// apple, banana, cherry

Nested Loops

for (var i = 1; i <= 3; i = i + 1) {
    for (var j = 1; j <= 3; j = j + 1) {
        print(i + " x " + j + " = " + (i * j));
    }
}