</head> <body> <h1>{...} (블록)</h1> <p>Blocks are one or more <a href="../Concepts.htm#statement">statements</a> enclosed in braces. Typically used with <a href="../Functions.htm#define">function definitions</a> and <a href="../Language.htm#control-flow">control flow statements</a>.</p> <pre class="Syntax"> { <i>Statements</i> }</pre> <h2 id="Remarks">논평</h2> <p>A block is used to bind two or more <a href="../Concepts.htm#statement">statements</a> together. It can also be used to change which <a href="../Language.htm#if-statement">If statement</a> an <a href="Else.htm">Else statement</a> belongs to, as in this example where the block forces the Else statement to belong to the first If statement rather than the second:</p> <pre>if (Var1 = 1) { if (Var2 = "abc") Sleep, 1 } else return</pre> <p>Although blocks can be used anywhere, currently they are only meaningful when used with <a href="../Functions.htm#define">function definitions</a>, <a href="../Language.htm#if-statement">If statements</a>, <a href="Else.htm">Else</a>, <a href="../Language.htm#loop-statement">Loop statements</a>, <a href="Try.htm">Try</a>, <a href="Catch.htm">Catch</a> or <a href="Finally.htm">Finally</a>.</p> <p>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). 그렇지만, 스크립트의 가독성을 향상시키고 유지관리성을 용이하게 하기 위해 그래야 할 경우가 있습니다.</p> <p>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.</p> <p id="otb"><strong>One True Brace (OTB, K&amp;R 스타일):</strong> OTB 스타일을 선택적으로 다음과 같은 경우에 사용할 수 있습니다: <a href="../Functions.htm#define">function definitions</a>, <a href="IfExpression.htm">If (expression)</a>, <a href="Else.htm">Else</a>, <a href="Loop.htm">Loop Count</a>, <a href="While.htm">While</a>, <a href="For.htm">For</a>, <a href="Try.htm">Try</a>, <a href="Catch.htm">Catch</a>, and <a href="Finally.htm">Finally</a>. 이 스타일은 블록의 시작 활괄호를 블록의 제어 서술문과 같은 줄에 배치합니다. 그 줄 아래 따로 두지 않습니다. 예를 들어:</p> <pre>MyFunction(x, y) { ... } if (x &lt; y) { ... } else { ... } Loop %RepeatCount% { ... } While x &lt; y { ... } For k, v in obj { ... } Try { ... } Catch e { ... } Finally { .... }</pre> <p>Similarly, a statement may exist to the right of a brace (except the open-brace of the One True Brace style). 예를 들어:</p> <pre>if (x = 1) { MsgBox 이 줄은 여는 괄호의 오른쪽에 나타납니다. IF-서술문이 참일 때마다 실행됩니다. MsgBox 이 줄은 다음 줄입니다. } MsgBox 이 줄은 닫는 괄호의 오른쪽에 나타납니다. 무조건 실행됩니다.</pre> <h2 id="Related">관련 항목</h2> <p><a href="../Functions.htm#define">Function Definitions</a>, <a href="../Language.htm#control-flow">Control Flow Statements</a>, <a href="../Language.htm#if-statement">If Statements</a>, <a href="Else.htm">Else</a>, <a href="../Language.htm#loop-statement">Loop Statements</a>, <a href="Try.htm">Try</a>, <a href="Catch.htm">Catch</a>, <a href="Finally.htm">Finally</a></p> <h2 id="Examples">예제</h2> <div class="ex" id="ExBasic"> <p><a class="ex_number" href="#ExBasic"></a> By enclosing the two statements <code>MsgBox, test1</code> and <code>Sleep, 5</code> with braces, the If statement knows that it should execute both if <var>x</var> is equal to 1.</p> <pre>if (x = 1) { MsgBox, test1 Sleep, 5 } else MsgBox, test2</pre> </div> </body> </html>