RETURN & EXIT ALL
RETURN exits an operation or query with a value. EXIT ALL terminates the entire query immediately. CLOSE ALL NESTS breaks out of all open blocks at once.
RETURN inside an operation
The primary use of RETURN — pass a value back to the caller from a DEFINE NEW OPERATION block. Execution of the operation stops at RETURN; the rest of the body is skipped.
DEFINE NEW OPERATION AS "classify"
OPEN NEST
IF !REQUEST(score) IS GREATER THAN 90
OPEN NEST RETURN "A" CLOSE NEST
ELSE IF !REQUEST(score) IS GREATER THAN 70
OPEN NEST RETURN "B" CLOSE NEST
ELSE IF !REQUEST(score) IS GREATER THAN 50
OPEN NEST RETURN "C" CLOSE NEST
ELSE OPEN NEST RETURN "F" CLOSE NEST
CLOSE NEST
NEW JSON OBJECT OPEN NEST SET "score" AS "85" CLOSE NEST SET ?args
AFTER EXECUTE OPERATION "classify" WITH ?args SET ?grade
AFTER EMIT ?grade
(* → "B" *)
Try it ›
(* RETURN with no value — exits operation returning null *)
DEFINE NEW OPERATION AS "maybe_process"
OPEN NEST
IF !REQUEST(skip) IS EQUAL TO "true"
OPEN NEST RETURN CLOSE NEST
ELSE OPEN NEST UPPER !REQUEST(text) SET ?result CLOSE NEST
AFTER RETURN ?result
CLOSE NEST
NEW JSON OBJECT OPEN NEST SET "text" AS "hello" AND SET "skip" AS "false" CLOSE NEST SET ?args
AFTER EXECUTE OPERATION "maybe_process" WITH ?args SET ?r
AFTER EMIT ?r
RETURN at query level
Outside an operation, RETURN ends the current query and sets the final result.
CALCULATE "10" SET ?n
IF ?n IS GREATER THAN 5
OPEN NEST RETURN "large" CLOSE NEST
ELSE OPEN NEST RETURN "small" CLOSE NEST
Try it ›
EXIT ALL
Immediately terminates the entire query from anywhere — inside nested blocks, inside FOREACH, inside operations. Nothing after EXIT ALL runs. The query returns whatever was last emitted.
EMIT "step 1"
AFTER EMIT "step 2"
AFTER EXIT ALL
AFTER EMIT "never reached"
Try it ›
(* EXIT ALL from inside a FOREACH *)
SPLIT "a,b,STOP,c,d" WITH "," SET ?items
AFTER FOREACH ?items AS ?item
OPEN NEST
IF ?item IS IDENTICAL TO "STOP"
OPEN NEST EXIT ALL CLOSE NEST
ELSE OPEN NEST EMIT ?item CLOSE NEST
CLOSE NEST
AFTER EMIT "never reached either"
Try it ›
CLOSE ALL NESTS
Breaks out of all currently open OPEN NEST blocks at once. Unlike EXIT ALL, execution continues at the statement after the outermost block. Use it to break deeply nested loops without exiting the entire query.
SPLIT "a,b,STOP,c,d" WITH "," SET ?items
AFTER FOREACH ?items AS ?item
OPEN NEST
IF ?item IS IDENTICAL TO "STOP"
OPEN NEST
CLOSE ALL NESTS (* breaks out of FOREACH and IF blocks *)
CLOSE NEST
ELSE OPEN NEST EMIT ?item CLOSE NEST
CLOSE NEST
AFTER EMIT "continued after break"
Try it ›
| Keyword | Scope | Effect |
RETURN ?val | Inside operation | Exit operation, pass value to caller |
RETURN ?val | Query level | End query, set final result |
RETURN | Either | Exit with null |
EXIT ALL | Anywhere | Terminate entire query immediately |
CLOSE ALL NESTS | Inside blocks | Break out of all open blocks, continue after outermost |