Informix Error -660
-660 Loop variable variable-name cannot be modified.
An attempt was made to modify the value of a loop variable in a FOR statement. Loop variables cannot be modified inside a loop.
Example of error:
FOR i IN (1,2,3,4) LET i = i + 1; -- error END FOR
Correction: Use another variable in the LET statement.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-660 fires when a FOR statement's loop variable is assigned a new value inside the loop body —
per the official guidance, loop variables are managed by the FOR statement itself and can't be
modified from within.
- A
LETstatement inside aFORloop assigning directly to the loop variable, per the official guidance — the direct, only cause. - An attempt to skip iterations or change the loop's direction by manipulating the loop variable's value mid-loop, a pattern that works in some general-purpose languages but isn't supported here.
Solutions / Resolution
- Use a different variable in the
LETstatement, per the official guidance's documented correction, rather than modifying the loop variable directly. - If early termination or a skip is genuinely needed, use
EXIT FOR/CONTINUE FORto control the loop's flow instead of trying to alter the loop variable's value.
Examples
The disallowed attempt
FOR i = 1 TO 10
LET i = i + 5; -- -660: i is the loop variable
...
END FOR;
Corrected — use a separate variable
DEFINE v_adjusted INT;
FOR i = 1 TO 10
LET v_adjusted = i + 5;
...
END FOR;
Or corrected — use EXIT FOR to change flow instead
FOR i = 1 TO 10
IF some_condition THEN
EXIT FOR;
END IF;
...
END FOR;
Diagnostic Checks
- Scan
LETstatements insideFORloop bodies for an assignment to the loop variable itself, and redirect it to a separate variable.
Related Errors / Related Topics
- -662 — "Loop variable variable-name specified more than once." A related
FOREACH/loop- variable restriction, about reusing a variable name rather than modifying it inside the loop.
Loop variables are managed entirely by the FOR statement — assign to a separate variable, or
use EXIT FOR/CONTINUE FOR to control flow instead.