Nitpick Control Flow Specification
Nitpick provides a robust set of control flow primitives ranging from standard C-style loops to state-tracked conditional loops and advanced pattern matching.
⚠️ CRITICAL SYNTAX RULE: Unlike
functions, structs, and traits (which must be terminated
with };), control flow blocks do NOT
end with semicolons. Adding a semicolon after the
closing brace of an if, while, or
pick block will cause a syntax error.
1. Branching
1.1 if /
else if / else
Standard conditional branching. Parentheses around the condition are required.
if (x == 1i32) {
// ...
} else if (x == 2i32) {
// ...
} else {
// ...
}
1.2 pick
(Switch/Match)
Nitpick’s equivalent to switch or
match. Cases are evaluated against the target
variable. * Case patterns must be wrapped in parentheses:
(value) { body } * Cases must be separated by
commas , * The default/catch-all case is
designated by (*) *
Fallthrough: Nitpick does not implicitly
fall through. To fall through to another case, you must
label the target case and use the fall label;
keyword.
pick (x) {
(0i32) { println("Zero"); },
one: (1i32) { fall two; },
two: (2i32) { println("One or Two"); },
(*) { println("Other"); }
}
2. Iteration
Nitpick supports break to exit the innermost
loop, and continue to skip to the next
iteration across all loop types.
2.1 while Loop
Standard condition-based loop.
while (x < 10i32) {
x += 1i32;
}
2.2
when / then / end
(State-Tracked Loop)
A specialized while loop that inherently
tracks how the loop terminated. It eliminates the
need for external state-tracking boolean flags.
when (x > 0i32) {
// Loop body
x -= 1i32;
} then {
// Executes ONLY if the loop completed normally (condition became false)
} end {
// Executes ONLY if the condition was false to begin with,
// OR if the loop exited prematurely via a `break`
}
2.3 for Loop
A standard C-style 3-part iteration loop (Init; Condition; Update).
for (int32:i = 0i32; i < 10i32; i++) {
// ...
}
2.4 Counted
Iteration (loop and till)
For rapid, highly-optimized counted iteration, Nitpick
offers loop and till. They
automatically manage the iteration counter and expose it
inside the block via the special $ keyword.
loop(start, limit, step)
loop(0i32, 10i32, 1i32) {
x += $; // '$' resolves to the current iteration counter (0, 1, ..., 9)
}
till(limit, step)
(Shorthand when starting from 0)
till(10i32, 1i32) {
x += $; // '$' ranges from 0 to 9
}