GPC operators and control flow
Build conditions and loops with comparison, logical, arithmetic, assignment, if, else, while, for, break, and continue.
Overview
GPC uses C-like expressions and control-flow statements. Parenthesize mixed conditions and keep loops bounded so a main pass can finish.
Controller values are integers, so comparisons should reflect the input's documented range and sign convention.
Key facts
- if and else select conditional paths.
- while and for can repeat statements within one execution pass.
- An unbounded loop can prevent normal script processing.
- Logical and comparison operators produce values used as conditions.
GPC syntax examples
Examples are intentionally small. Replace identifiers only with values documented for your target.
int i;
main {
if (get_val(XB1_A) > 50) {
for (i = 0; i < 3; i = i + 1) {
// bounded work
}
}
}Functions, commands, and terms
Names below are catalog entries, not guessed signatures. Open the official sources for current parameter and return-value details.
ifkeywordExecutes a block when its expression is true.
elsekeywordProvides the alternative branch of an if statement.
else ifkeywordTests another condition after a preceding condition is false.
whilekeywordRepeats a block while its condition remains true.
do whilekeywordRuns a block once, then repeats it while its condition is true.
forkeywordExpresses initialization, condition, and update for a loop.
breakkeywordLeaves the nearest loop.
Common mistakes
Using assignment where comparison was intended.
Creating an endless while loop.
Combining && and || without clarifying precedence.
Official GPC sources
Use these first-party references to confirm exact syntax and runtime behavior for your installed firmware and Studio version.
Related GPC references
Understand signed 16-bit runtime values, global storage, local scope, initialization, and safe array indexing.
Executioninit and main execution modelKnow what runs once, what loops, and why blocking or one-time work belongs in the correct execution block.
LanguageUser functions in GPCExtract reusable synchronous calculations while respecting parameter, return, recursion, and combo-only timing rules.