Understanding blocks
The Bosque block statements are nothing more than sequences of statements; they usually define a scope for the variables declared within the block and represent a contained execution context. Typically, they are delimited by curly brackets.
Let's see the next code:
var x = 7; { var y = 5; y = x + 3; }
As we see in the previous code, we see a variable x
declared outside the block's context, which is accessible from the block, but the variable y
is available only for the instructions contained by the block.
The blocks are present in several of the statements presented in this chapter. Let's see some examples to identify them better:
if ( true ) { // this is a block } else { // this is another block }
We have two blocks in a common if
declaration. We also have a block in a function
declaration:
function try(): String { ...