Continuing the series, another Lisp directive that newcomers arriving from C++ might not immediately encounter is block. This is a simple flow-control statement which can almost be emulated using a goto in C++.
What block does is to create a named collection of statements, such that flow can immediately exit the block when return-from is used. In C++, you could imagine putting a label immediately after the last statement in the Lisp block, and then using goto to branch to that label. This is not quite an exact parallel because a Lisp block can return a value, while that concept doesn’t apply in C++.
In Lisp, a block that exits normally returns the result of its last statement. In the event of a branch with return-from, an optional second argument is the return value of the block, otherwise the block returns nil.
Note that the Lisp return statement does not take a name as an argument, and returns from the innermost enclosing unnamed (nil) block,
whether named or not. This might be a block you created with the block directive, or it might be an implicit block surrounding one of the looping constructs, so for safety you’re encouraged to use named blocks and return-from when that is appropriate. When using a looping construct like do, dolist, or dotimes, a bare return reads like a break in C++.