From 49e7f51995331cc41d1d3e2cbd6a41c22db60108 Mon Sep 17 00:00:00 2001 From: takejohn Date: Sat, 1 Feb 2025 16:14:05 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=A9=E3=83=99=E3=83=AB=E6=A7=8B=E6=96=87?= =?UTF-8?q?=E3=81=AE=E8=AA=AC=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/references/syntax.md | 36 ++++++++++++++++++++++++++++++++++++ docs/ja/references/syntax.md | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) 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 +```