{...} (블록)

Blocks are one or more statements enclosed in braces. Typically used with function definitions and control flow statements.

{
    Statements
}

논평

A block is used to bind two or more statements together. It can also be used to change which If statement an Else statement belongs to, as in this example where the block forces the Else statement to belong to the first If statement rather than the second:

if (Var1 = 1)
{
    if (Var2 = "abc")
        Sleep, 1
}
else
    return

Although blocks can be used anywhere, currently they are only meaningful when used with function definitions, If statements, Else, Loop statements, Try, Catch or Finally.

If any of the control flow statements mentioned above has only a single statement, that statement need not be enclosed in a block (this does not work for function definitions). 그렇지만, 스크립트의 가독성을 향상시키고 유지관리성을 용이하게 하기 위해 그래야 할 경우가 있습니다.

A block may be empty (contain zero statements), which may be useful in cases where you want to comment out the contents of the block without removing the block itself.

One True Brace (OTB, K&R 스타일): OTB 스타일을 선택적으로 다음과 같은 경우에 사용할 수 있습니다: function definitions, If (expression), Else, Loop Count, While, For, Try, Catch, and Finally. 이 스타일은 블록의 시작 활괄호를 블록의 제어 서술문과 같은 줄에 배치합니다. 그 줄 아래 따로 두지 않습니다. 예를 들어:

MyFunction(x, y) {
    ...
}
if (x < y) {
    ...
} else {
    ...
}
Loop %RepeatCount% {
    ...
}
While x < y {
    ...
}
For k, v in obj {
    ...
}
Try {
    ...
} Catch e {
    ...
} Finally {
    ....
}

Similarly, a statement may exist to the right of a brace (except the open-brace of the One True Brace style). 예를 들어:

if (x = 1)
{ MsgBox 이 줄은 여는 괄호의 오른쪽에 나타납니다. IF-서술문이 참일 때마다 실행됩니다.
    MsgBox 이 줄은 다음 줄입니다.
} MsgBox 이 줄은 닫는 괄호의 오른쪽에 나타납니다. 무조건 실행됩니다.

Function Definitions, Control Flow Statements, If Statements, Else, Loop Statements, Try, Catch, Finally

예제

By enclosing the two statements MsgBox, test1 and Sleep, 5 with braces, the If statement knows that it should execute both if x is equal to 1.

if (x = 1)
{
    MsgBox, test1
    Sleep, 5
}
else
    MsgBox, test2