diff --git a/docs/en/references/syntax.md b/docs/en/references/syntax.md index 643d5e3..92883fb 100644 --- a/docs/en/references/syntax.md +++ b/docs/en/references/syntax.md @@ -419,3 +419,39 @@ var foo = exists bar // Variable foo exists, so true var bar = exists foo ``` + +## Labeled Statements and Expressions +The following statements and expressions can be labeled. +- [`for`](#for) +- [`each`](#each) +- [`while`](#while) +- [`do-while`](#do-while) +- [`loop`](#loop) +- [`if`](#if) +- [`eval`](#eval) +- [`match`](#match) + +You can exit outer blocks using labeled `break` and `continue` statements in nested blocks. +```aiscript playground +#outer: for let x, 3 { + for let y, 2 { + if (x == 1 && y == 1) { + continue #outer + } + <: [x, y] + } +} +``` + +A `break` statement associated with `eval`, `if`, or `match` can include a value. +```aiscript playground +<: #label1: eval { + break #label1 + 1 +} // => null + +<: #label2: eval { + break #label2 2 + 3 +} // => 2 +``` diff --git a/docs/ja/references/syntax.md b/docs/ja/references/syntax.md index 8a0c1b6..2b22358 100644 --- a/docs/ja/references/syntax.md +++ b/docs/ja/references/syntax.md @@ -419,3 +419,39 @@ var foo = exists bar // 変数fooが存在するためtrue var bar = exists foo ``` + +## ラベル構文 +以下の文や式にラベルを付与することができます。 +- [`for`](#for) +- [`each`](#each) +- [`while`](#while) +- [`do-while`](#do-while) +- [`loop`](#loop) +- [`if`](#if) +- [`eval`](#eval) +- [`match`](#match) + +ネストしたブロック内でラベルを付与した`break`文や`continue`文を使用することで外側のブロックから脱出することができます。 +```aiscript playground +#outer: for let x, 3 { + for let y, 2 { + if (x == 1 && y == 1) { + continue #outer + } + <: [x, y] + } +} +``` + +`eval`または`if`, `match`に対応するbreak文には値を指定することができます。 +```aiscript playground +<: #label1: eval { + break #label1 + 1 +} // => null + +<: #label2: eval { + break #label2 2 + 3 +} // => 2 +```