Cesium logo Cesium

Control Flow

November 17, 2026

If-Else Statements

if (condition) {
  printf("Condition is true\n");
} else if (other_condition) {
  printf("Other condition is true\n");
} else {
  printf("No conditions met\n");
}

While Loops

// While loop
i32 count = 0;
while (count < 10) {
  printf("Count: {}\n", count);
  count++;
}

Do-While Loops

// Do-while loop
do {
  input = get_user_input();
} while (input != "quit");

For Loops with Ranges

// For loops with ranges
for (i32 i = 0..10) {        // 0,1,2,...,9 (exclusive)
  printf("i = {}\n", i);
}

for (i32 i = 0..=10) {       // 0,1,2,...,10 (inclusive)
  printf("i = {}\n", i);
}

for (i32 i = 0..2..=10) {    // 0,2,4,6,8,10 (step 2)
  printf("i = {}\n", i);
}

Collection Iteration

// Iteration over collections
i32 numbers[5] = {1, 2, 3, 4, 5};
for (i32 value = numbers) {
  printf("Value: {}\n", value);
}

Switch Statements

// Switch statements
switch (value) {
  case (1) { printf("One\n"); }
  case (2, 3) { printf("Two or Three\n"); }
  case (10..=20) { printf("Between 10 and 20\n"); }
  else { printf("Something else\n"); }
}

Fallthrough Behavior

// Optional fallthrough
fallthrough switch (status) {
  case (STARTING) {
    initialize();
    // falls through
  }
  case (RUNNING) {
    process();
    break;  // explicit break
  }
  case (STOPPED) {
    cleanup();
  }
}

Type Matching

// Type matching
Number num = get_number();  // Number = i32|f64
switch (typeof(num)) {
  case (i32) {
    i32 val = num as i32;
    printf("Integer: {}\n", val);
  }
  case (f64) {
    f64 val = num as f64;
    printf("Float: {}\n", val);
  }
}

Break and Continue

for (i32 i = 0..100) {
  if (i % 2 == 0) {
    continue;  // skip even numbers
  }
  if (i > 50) {
    break;     // exit loop
  }
  printf("{}\n", i);
}

Range Syntax

Cesium provides several range operators for convenient iteration:

SyntaxDescriptionExample
a..bExclusive range0..10 → 0,1,2,…,9
a..=bInclusive range0..=10 → 0,1,2,…,10
a..step..=bStepped inclusive0..2..=10 → 0,2,4,6,8,10
a..step..bStepped exclusive0..2..10 → 0,2,4,6,8
Cesium 0.2.0, in development (dev at 53dc38a) · GitHub