Informix Error -4315
-4315 The program cannot exit a FOREACH statement at this point because
it is not within a FOREACH statement.This CONTINUE or EXIT statement uses the FOREACH keyword, but it is not located within a FOREACH loop. Either the statement is in error, or some other error has prevented 4GL from recognizing the FOREACH statement.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-4315 fires when CONTINUE FOREACH or EXIT FOREACH appears outside a FOREACH loop — per
the official guidance, either the statement is misplaced, or some other error prevented 4GL
from recognizing the enclosing FOREACH statement.
CONTINUE FOREACH/EXIT FOREACHused outside aFOREACHloop, per the official guidance — the direct cause.- A separate error prevented the enclosing
FOREACHstatement from being recognized, per the official guidance — a related possible cause.
Solutions / Resolution
- Move the
CONTINUE FOREACH/EXIT FOREACHstatement inside aFOREACHloop, or - Check for other errors preventing the
FOREACHstatement from being recognized, per the official guidance.
Examples
EXIT FOREACH outside a FOREACH loop
FUNCTION process()
EXIT FOREACH
-- -4315: not inside a FOREACH loop
END FUNCTION
Corrected
FOREACH cur INTO rec.*
IF rec.order_id = 0 THEN
EXIT FOREACH
END IF
END FOREACH
Diagnostic Checks
- Check whether the
CONTINUE FOREACH/EXIT FOREACHstatement is inside aFOREACHloop, and check for other errors affecting the enclosingFOREACHstatement if it should be.
Related Errors / Related Topics
- -4314 — "The program cannot continue or exit a menu at this point because it is not
within a MENU statement." The same pattern applied to
MENUinstead ofFOREACH.
CONTINUE FOREACH/EXIT FOREACH is used outside a FOREACH loop — move it inside, or check
for errors affecting the FOREACH statement's recognition.