Block

Summary

Blocks are used to group multiple statements together.

Syntax

{
    statement1;
    statement2;
    statement3;
}

Parameters

statementN
The statement(s) to execute.

Description

Blocks are used for grouping multiple statements together. The resulting block is treated as a single statement by itself. Blocks are typically used to group statements for the bodies of control flow statements such as if statements:

1
2
3
4
5
int x = 1;
if (x >= 1) {
    int y = 2;
    int z = 3;
}

It is also possible to have zero statements in a block. This is known as an "empty block".

Blocks do not end with a semicolon.

Blocks create a "scope" in JS++. This is in contrast to JavaScript which creates scopes at the function level. For more information on scopes and scoping, consult the scoping documentation.

See Also

Share

HTML | BBCode | Direct Link