For the complete documentation index, see llms.txt. This page is also available as Markdown.

Flow control

if, else if, else

if(mode == 0) {
    // first path
} else if(mode == 1) {
    // second path
} else {
    // fallback
}

switch, case, default

switch(mode) {
    case 0: {
        set_val(TRACE_1, 10);
        break;
    }
    case 1: {
        set_val(TRACE_1, 20);
        break;
    }
    default: {
        mode = 0;
        break;
    }
}

Case values must be compile-time constants and unique. Braces are required around case bodies. Omit break only when fallthrough is deliberate and documented.

Deliberate fallthrough still produces GPC6018. GPC has no annotation to mark it as intentional, so the warning appears on every case that falls through — expect it, and document the intent in a comment.

for

while

do ... while


break and continue

break exits the nearest loop or switch. continue skips to the next iteration of the nearest loop. Neither is valid outside its allowed context.


return

return; immediately exits the current user-created function. return expression; also supplies the function's result:

A bare return; exits without a value. Do not mix bare and valued returns in the same function. If execution reaches the end of a user function without returning a value, its result is 0; callers may also ignore a user function's result.

All real-time loops must have a provable quick exit. A loop that waits for a future physical event will lock the current VM cycle; use persistent state evaluated across main cycles instead.

Last updated