$ZL[EVEL] contains an integer value indicating the "level of nesting" caused by DO commands, XECUTE commands, and extrinsic functions in the M invocation stack.
$ZLEVEL has an initial value of one (1) and increments by one with each DO, XECUTE or extrinsic function. Any QUIT that does not terminate a FOR loop decrements $ZLEVEL. ZGOTO may also reduce $ZLEVEL. In accordance with the M standard, a FOR command does not increase $ZLEVEL. M routines cannot modify $ZLEVEL with the SET or NEW commands.
Use $ZLEVEL in debugging or in an error-handling mechanism to capture a level for later use in a ZGOTO argument.
Example:
GTM>ZPRINT ^ZLEV ADO B WRITE X,! QUIT BGOTO C QUIT CDO D QUIT DSET X=$ZLEVEL QUIT GTM>DO ^ZLEV 4
This program, executed from Direct Mode, produces a value of 4 for $ZLEVEL. Note that if we RUN this program from the DCL level the value of $ZLEVEL is three (3).