LanguageUpdated 2026-07-24

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.

Bounded conditional logicexample.gpc
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.

NameKindPurpose
ifkeyword

Executes a block when its expression is true.

elsekeyword

Provides the alternative branch of an if statement.

else ifkeyword

Tests another condition after a preceding condition is false.

whilekeyword

Repeats a block while its condition remains true.

do whilekeyword

Runs a block once, then repeats it while its condition is true.

forkeyword

Expresses initialization, condition, and update for a loop.

breakkeyword

Leaves 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