Informix Error -596: Bad EXIT/CONTINUE statement. Not within a statement-name loop.
Cause and resolution
Bad EXIT/CONTINUE statement. Not within a statement-name loop.
The SPL routine EXIT and CONTINUE statements must be placed within a FOREACH, WHILE, or FOR loop.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-596 fires when an SPL routine's EXIT/CONTINUE statement appears outside any loop — per the
official guidance, these statements must be placed within a FOREACH, WHILE, or FOR loop.
EXIT/CONTINUEplaced at the routine's top level, outside any loop construct — the direct, only cause.EXIT/CONTINUEplaced inside anIFblock that isn't itself nested inside a loop, mistaking conditional nesting for loop nesting.- A loop restructured or removed during editing, leaving a now-orphaned
EXIT/CONTINUEstatement behind that used to be inside it.
Solutions / Resolution
- Move the
EXIT/CONTINUEstatement inside aFOREACH,WHILE, orFORloop, per the official guidance. - Confirm the loop actually wraps the statement, not just an
IFblock that happens to sit near a loop — trace the actual nesting ofBEGIN/ENDor loop boundaries. - If the intent was to exit the routine entirely rather than a loop, use
RETURNinstead ofEXIT, sinceEXITspecifically exits a loop, not the routine.
Examples
The disallowed placement
CREATE PROCEDURE process_orders()
DEFINE v_status CHAR(10);
IF v_status = 'cancelled' THEN
EXIT;
END IF;
END PROCEDURE;
-- -596: EXIT isn't inside a FOREACH/WHILE/FOR loop
Corrected — inside a loop
CREATE PROCEDURE process_orders()
DEFINE v_status CHAR(10);
FOREACH SELECT status INTO v_status FROM orders
IF v_status = 'cancelled' THEN
EXIT FOREACH;
END IF;
END FOREACH;
END PROCEDURE;
Diagnostic Checks
- Trace the actual loop nesting around every
EXIT/CONTINUEstatement in the routine, confirming aFOREACH/WHILE/FORgenuinely wraps it, not just anIFblock.
Related Errors / Related Topics
No closely related error codes are cross-referenced for -596 in this set yet.
EXIT/CONTINUE require an actual enclosing loop — confirm the nesting, and use RETURN
instead if exiting the routine itself was the real intent.