SultanC
  1. Home
  2. Examples
  3. Control flow

A C-style `for` loop with `continue` and `break`

control_flow/for_loop.sn
// A C-style `for` loop with `continue` and `break`.
import std.io.println;
import std.text.number;

def main(): int {
    let total: mutable int = 0;
    for (let i: mutable int = 1; i <= 100; i := i + 1) {
        if (i % 3 == 0) { continue; };
        if (i > 10) { break; };
        total := total + i;
    }
    println(int_to_text(total));
    return 0;
}

Run it

With the interpreter, without compiling:

./build/sultanc run examples/en/control_flow/for_loop.sn

Or compile it to an executable:

./build/sultanc examples/en/control_flow/for_loop.sn -o build/example && ./build/example

Source on GitHub   All examples