Nested blocks are important for controlling program flow. They also come into play when a block is exited without an explicit leave block statement (described in Leaving (Exiting) a Block). When using nested blocks, name each one for clarity.
Blocks can be nested within other blocks, creating a program that contains many levels of responses, ranging from the innermost to the outermost. One way of understanding nested blocks is to consider the entire ESL program itself as a block. The following is an example of a nested block:
# Action routine:
action DialBlock is
send "AT\r\n" to DJNS
begin CheckOK1
response to line "OK" from DJNS
leave block
response to line "ERROR" from DJNS
action ErrorWait
end CheckOK1
change Prompt to
move to (xsize/2) (ysize/2)
font "large" text center "Dialing ..."
send "ATDT" Phonenum "\r\n" to DJNS
begin CheckConnect # Outer block
response to line "Connect" from DJNS
action Logon
leave block
response to line "Error" from DJNS
action ErrorWait
response to Quit
send "\r\n" to DJNS
begin CheckOK2 # Inner block
response to line "OK" from DJNS
leave block
response to line "ERROR" from DJNS
action ErrorWait
end CheckOK2
leave block
end CheckConnect
When blocks are nested, control can be transferred from one block to any of the blocks that are outside that block (at a higher level of nesting). There might be more than one block at any given level, but only one of these can be active at any given time. These situations are discussed in the following section.