C Compiler Logo

Invalid Syntax in Control Statements

Invalid Syntax in Control Statements

syntax

error: expected expression before ')' token

Description

Incorrect syntax in control statements like if, for, while, or switch.

Common Causes

Example of Error

Error Code

int main() {
    int i;
    for (i = 0; i < 10; ) {
        printf("%d\n", i);
    }
    return 0;
}

Solution

Correct the syntax of the control statement.

Corrected Code

int main() {
    int i;
    for (i = 0; i < 10; i++) {
        printf("%d\n", i);
    }
    return 0;
}

Additional Tips