diff options
| author | Li Jin <dragon-fly@qq.com> | 2026-02-15 05:49:13 +0000 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2026-02-15 07:36:30 +0000 |
| commit | cf5b1b4a68d762e6e33cac8367611ecea15fa942 (patch) | |
| tree | 25de1a4113d26882c0135e38b7ff166efbc39969 /doc | |
| parent | ecd8f3bfd07e91d04e0a2d72f4a50f9cc6c75433 (diff) | |
| download | yuescript-cf5b1b4a68d762e6e33cac8367611ecea15fa942.tar.gz yuescript-cf5b1b4a68d762e6e33cac8367611ecea15fa942.tar.bz2 yuescript-cf5b1b4a68d762e6e33cac8367611ecea15fa942.zip | |
- Added goto.md documentation files in all languages (en, de, zh, pt-br, id-id)
- Updated conditionals.md to include goto statement references
- Updated VitePress config to include new goto documentation pages
- Updated makefile for goto documentation compilation
- Added test outputs for goto examples in all languages
- Updated yue.cpp core implementation
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/docs/.vitepress/config.mts | 9 | ||||
| -rw-r--r-- | doc/docs/de/doc/control-flow/conditionals.md | 58 | ||||
| -rw-r--r-- | doc/docs/de/doc/control-flow/goto.md | 106 | ||||
| -rw-r--r-- | doc/docs/doc/control-flow/conditionals.md | 58 | ||||
| -rw-r--r-- | doc/docs/doc/control-flow/goto.md | 106 | ||||
| -rw-r--r-- | doc/docs/id-id/doc/control-flow/conditionals.md | 58 | ||||
| -rw-r--r-- | doc/docs/id-id/doc/control-flow/goto.md | 106 | ||||
| -rw-r--r-- | doc/docs/pt-br/doc/control-flow/conditionals.md | 58 | ||||
| -rw-r--r-- | doc/docs/pt-br/doc/control-flow/goto.md | 106 | ||||
| -rw-r--r-- | doc/docs/zh/doc/control-flow/conditionals.md | 58 | ||||
| -rw-r--r-- | doc/docs/zh/doc/control-flow/goto.md | 106 | ||||
| -rw-r--r-- | doc/yue-de.md | 58 | ||||
| -rw-r--r-- | doc/yue-en.md | 58 | ||||
| -rw-r--r-- | doc/yue-id-id.md | 58 | ||||
| -rw-r--r-- | doc/yue-pt-br.md | 58 | ||||
| -rw-r--r-- | doc/yue-zh.md | 58 |
16 files changed, 1119 insertions, 0 deletions
diff --git a/doc/docs/.vitepress/config.mts b/doc/docs/.vitepress/config.mts index 635d087..872791c 100644 --- a/doc/docs/.vitepress/config.mts +++ b/doc/docs/.vitepress/config.mts | |||
| @@ -55,6 +55,7 @@ const sidebarText = { | |||
| 55 | whileLoop: "While-Schleife", | 55 | whileLoop: "While-Schleife", |
| 56 | continueStatement: "Continue-Anweisung", | 56 | continueStatement: "Continue-Anweisung", |
| 57 | conditionals: "Bedingungen", | 57 | conditionals: "Bedingungen", |
| 58 | gotoStatement: "Goto und Labels", | ||
| 58 | lineDecorators: "Zeilen-Dekoratoren", | 59 | lineDecorators: "Zeilen-Dekoratoren", |
| 59 | switch: "Switch", | 60 | switch: "Switch", |
| 60 | objectOrientedProgramming: "Objektorientierte Programmierung", | 61 | objectOrientedProgramming: "Objektorientierte Programmierung", |
| @@ -89,6 +90,7 @@ const sidebarText = { | |||
| 89 | whileLoop: "While Loop", | 90 | whileLoop: "While Loop", |
| 90 | continueStatement: "Continue Statement", | 91 | continueStatement: "Continue Statement", |
| 91 | conditionals: "Conditionals", | 92 | conditionals: "Conditionals", |
| 93 | gotoStatement: "Goto and Labels", | ||
| 92 | lineDecorators: "Line Decorators", | 94 | lineDecorators: "Line Decorators", |
| 93 | switch: "Switch", | 95 | switch: "Switch", |
| 94 | objectOrientedProgramming: "Object Oriented Programming", | 96 | objectOrientedProgramming: "Object Oriented Programming", |
| @@ -123,6 +125,7 @@ const sidebarText = { | |||
| 123 | whileLoop: "Perulangan While", | 125 | whileLoop: "Perulangan While", |
| 124 | continueStatement: "Pernyataan Lanjutkan", | 126 | continueStatement: "Pernyataan Lanjutkan", |
| 125 | conditionals: "Percabangan", | 127 | conditionals: "Percabangan", |
| 128 | gotoStatement: "Goto dan Label", | ||
| 126 | lineDecorators: "Dekorator Baris", | 129 | lineDecorators: "Dekorator Baris", |
| 127 | switch: "Switch", | 130 | switch: "Switch", |
| 128 | objectOrientedProgramming: "Pemrograman Berorientasi Objek", | 131 | objectOrientedProgramming: "Pemrograman Berorientasi Objek", |
| @@ -157,6 +160,7 @@ const sidebarText = { | |||
| 157 | whileLoop: "Laço while", | 160 | whileLoop: "Laço while", |
| 158 | continueStatement: "Instrução continue", | 161 | continueStatement: "Instrução continue", |
| 159 | conditionals: "Condicionais", | 162 | conditionals: "Condicionais", |
| 163 | gotoStatement: "Goto e Rótulos", | ||
| 160 | lineDecorators: "Decoradores de linha", | 164 | lineDecorators: "Decoradores de linha", |
| 161 | switch: "Switch", | 165 | switch: "Switch", |
| 162 | objectOrientedProgramming: "Programação orientada a objetos", | 166 | objectOrientedProgramming: "Programação orientada a objetos", |
| @@ -191,6 +195,7 @@ const sidebarText = { | |||
| 191 | whileLoop: "while 循环", | 195 | whileLoop: "while 循环", |
| 192 | continueStatement: "continue 语句", | 196 | continueStatement: "continue 语句", |
| 193 | conditionals: "条件语句", | 197 | conditionals: "条件语句", |
| 198 | gotoStatement: "goto 语句与标签", | ||
| 194 | lineDecorators: "代码行修饰符", | 199 | lineDecorators: "代码行修饰符", |
| 195 | switch: "switch 语句", | 200 | switch: "switch 语句", |
| 196 | objectOrientedProgramming: "面向对象编程", | 201 | objectOrientedProgramming: "面向对象编程", |
| @@ -363,6 +368,10 @@ function createSidebar(basePath: string, locale: SidebarLocale) { | |||
| 363 | text: text.continueStatement, | 368 | text: text.continueStatement, |
| 364 | link: `${basePath}/control-flow/continue`, | 369 | link: `${basePath}/control-flow/continue`, |
| 365 | }, | 370 | }, |
| 371 | { | ||
| 372 | text: text.gotoStatement, | ||
| 373 | link: `${basePath}/control-flow/goto`, | ||
| 374 | }, | ||
| 366 | { text: text.switch, link: `${basePath}/control-flow/switch` }, | 375 | { text: text.switch, link: `${basePath}/control-flow/switch` }, |
| 367 | ], | 376 | ], |
| 368 | }, | 377 | }, |
diff --git a/doc/docs/de/doc/control-flow/conditionals.md b/doc/docs/de/doc/control-flow/conditionals.md index 56663d1..0d2574d 100644 --- a/doc/docs/de/doc/control-flow/conditionals.md +++ b/doc/docs/de/doc/control-flow/conditionals.md | |||
| @@ -143,3 +143,61 @@ if a in list | |||
| 143 | ``` | 143 | ``` |
| 144 | 144 | ||
| 145 | </YueDisplay> | 145 | </YueDisplay> |
| 146 | |||
| 147 | Der `in`-Operator kann auch mit Tabellen verwendet werden und unterstützt die Variante `not in` für Verneinungen: | ||
| 148 | |||
| 149 | ```yuescript | ||
| 150 | has = "foo" in {"bar", "foo"} | ||
| 151 | |||
| 152 | if a in {1, 2, 3} | ||
| 153 | print "a ist in der Tabelle" | ||
| 154 | |||
| 155 | not_exist = item not in list | ||
| 156 | |||
| 157 | check = -> value not in table | ||
| 158 | ``` | ||
| 159 | |||
| 160 | <YueDisplay> | ||
| 161 | |||
| 162 | ```yue | ||
| 163 | has = "foo" in {"bar", "foo"} | ||
| 164 | |||
| 165 | if a in {1, 2, 3} | ||
| 166 | print "a ist in der Tabelle" | ||
| 167 | |||
| 168 | not_exist = item not in list | ||
| 169 | |||
| 170 | check = -> value not in table | ||
| 171 | ``` | ||
| 172 | |||
| 173 | </YueDisplay> | ||
| 174 | |||
| 175 | Eine Ein-Element-Liste oder Tabelle prüft auf Gleichheit mit diesem Element: | ||
| 176 | |||
| 177 | ```yuescript | ||
| 178 | -- [1,] prüft, ob wert == 1 | ||
| 179 | c = a in [1,] | ||
| 180 | |||
| 181 | -- {1} prüft auch, ob wert == 1 | ||
| 182 | c = a in {1} | ||
| 183 | |||
| 184 | -- Ohne Komma ist [1] ein Indexzugriff (tb[1]) | ||
| 185 | with tb | ||
| 186 | c = a in [1] | ||
| 187 | ``` | ||
| 188 | |||
| 189 | <YueDisplay> | ||
| 190 | |||
| 191 | ```yue | ||
| 192 | -- [1,] prüft, ob wert == 1 | ||
| 193 | c = a in [1,] | ||
| 194 | |||
| 195 | -- {1} prüft auch, ob wert == 1 | ||
| 196 | c = a in {1} | ||
| 197 | |||
| 198 | -- Ohne Komma ist [1] ein Indexzugriff (tb[1]) | ||
| 199 | with tb | ||
| 200 | c = a in [1] | ||
| 201 | ``` | ||
| 202 | |||
| 203 | </YueDisplay> | ||
diff --git a/doc/docs/de/doc/control-flow/goto.md b/doc/docs/de/doc/control-flow/goto.md new file mode 100644 index 0000000..0e2a415 --- /dev/null +++ b/doc/docs/de/doc/control-flow/goto.md | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | # Goto | ||
| 2 | |||
| 3 | YueScript unterstützt die goto-Anweisung und die Label-Syntax zur Steuerung des Programmflusses, wobei die gleichen Regeln wie bei Luas goto-Anweisung gelten. **Hinweis:** Die goto-Anweisung erfordert Lua 5.2 oder höher. Beim Kompilieren zu Lua 5.1 führt die Verwendung der goto-Syntax zu einem Kompilierfehler. | ||
| 4 | |||
| 5 | Ein Label wird mit doppelten Doppelpunkten definiert: | ||
| 6 | |||
| 7 | ```yuescript | ||
| 8 | ::start:: | ||
| 9 | ::done:: | ||
| 10 | ::mein_label:: | ||
| 11 | ``` | ||
| 12 | |||
| 13 | <YueDisplay> | ||
| 14 | |||
| 15 | ```yue | ||
| 16 | ::start:: | ||
| 17 | ::done:: | ||
| 18 | ::mein_label:: | ||
| 19 | ``` | ||
| 20 | |||
| 21 | </YueDisplay> | ||
| 22 | |||
| 23 | Die goto-Anweisung springt zu einem angegebenen Label: | ||
| 24 | |||
| 25 | ```yuescript | ||
| 26 | a = 0 | ||
| 27 | ::start:: | ||
| 28 | a += 1 | ||
| 29 | goto done if a == 5 | ||
| 30 | goto start | ||
| 31 | ::done:: | ||
| 32 | print "a ist jetzt 5" | ||
| 33 | ``` | ||
| 34 | |||
| 35 | <YueDisplay> | ||
| 36 | |||
| 37 | ```yue | ||
| 38 | a = 0 | ||
| 39 | ::start:: | ||
| 40 | a += 1 | ||
| 41 | goto done if a == 5 | ||
| 42 | goto start | ||
| 43 | ::done:: | ||
| 44 | print "a ist jetzt 5" | ||
| 45 | ``` | ||
| 46 | |||
| 47 | </YueDisplay> | ||
| 48 | |||
| 49 | Die goto-Anweisung ist nützlich, um aus tief verschachtelten Schleifen zu springen: | ||
| 50 | |||
| 51 | ```yuescript | ||
| 52 | for z = 1, 10 | ||
| 53 | for y = 1, 10 do for x = 1, 10 | ||
| 54 | if x^2 + y^2 == z^2 | ||
| 55 | print 'Pythagoreisches Tripel gefunden:', x, y, z | ||
| 56 | goto ok | ||
| 57 | ::ok:: | ||
| 58 | ``` | ||
| 59 | |||
| 60 | <YueDisplay> | ||
| 61 | |||
| 62 | ```yue | ||
| 63 | for z = 1, 10 | ||
| 64 | for y = 1, 10 do for x = 1, 10 | ||
| 65 | if x^2 + y^2 == z^2 | ||
| 66 | print 'Pythagoreisches Tripel gefunden:', x, y, z | ||
| 67 | goto ok | ||
| 68 | ::ok:: | ||
| 69 | ``` | ||
| 70 | |||
| 71 | </YueDisplay> | ||
| 72 | |||
| 73 | Sie können auch Labels verwenden, um zu einer bestimmten Schleifenebene zu springen: | ||
| 74 | |||
| 75 | ```yuescript | ||
| 76 | for z = 1, 10 | ||
| 77 | for y = 1, 10 | ||
| 78 | for x = 1, 10 | ||
| 79 | if x^2 + y^2 == z^2 | ||
| 80 | print 'Pythagoreisches Tripel gefunden:', x, y, z | ||
| 81 | print 'versuche nächstes z...' | ||
| 82 | goto zcontinue | ||
| 83 | ::zcontinue:: | ||
| 84 | ``` | ||
| 85 | |||
| 86 | <YueDisplay> | ||
| 87 | |||
| 88 | ```yue | ||
| 89 | for z = 1, 10 | ||
| 90 | for y = 1, 10 | ||
| 91 | for x = 1, 10 | ||
| 92 | if x^2 + y^2 == z^2 | ||
| 93 | print 'Pythagoreisches Tripel gefunden:', x, y, z | ||
| 94 | print 'versuche nächstes z...' | ||
| 95 | goto zcontinue | ||
| 96 | ::zcontinue:: | ||
| 97 | ``` | ||
| 98 | |||
| 99 | </YueDisplay> | ||
| 100 | |||
| 101 | ## Hinweise | ||
| 102 | |||
| 103 | - Labels müssen innerhalb ihres Geltungsbereichs eindeutig sein | ||
| 104 | - goto kann zu Labels auf derselben oder äußeren Geltungsbereichsebenen springen | ||
| 105 | - goto kann nicht in innere Geltungsbereiche springen (wie in Blöcke oder Schleifen) | ||
| 106 | - Verwenden Sie goto sparsam, da es den Code schwieriger zu lesen und zu warten machen kann | ||
diff --git a/doc/docs/doc/control-flow/conditionals.md b/doc/docs/doc/control-flow/conditionals.md index 1bcc838..ca29fda 100644 --- a/doc/docs/doc/control-flow/conditionals.md +++ b/doc/docs/doc/control-flow/conditionals.md | |||
| @@ -143,3 +143,61 @@ if a in list | |||
| 143 | ``` | 143 | ``` |
| 144 | 144 | ||
| 145 | </YueDisplay> | 145 | </YueDisplay> |
| 146 | |||
| 147 | The `in` operator can also be used with tables and supports the `not in` variant for negation: | ||
| 148 | |||
| 149 | ```yuescript | ||
| 150 | has = "foo" in {"bar", "foo"} | ||
| 151 | |||
| 152 | if a in {1, 2, 3} | ||
| 153 | print "a is in the table" | ||
| 154 | |||
| 155 | not_exist = item not in list | ||
| 156 | |||
| 157 | check = -> value not in table | ||
| 158 | ``` | ||
| 159 | |||
| 160 | <YueDisplay> | ||
| 161 | |||
| 162 | ```yue | ||
| 163 | has = "foo" in {"bar", "foo"} | ||
| 164 | |||
| 165 | if a in {1, 2, 3} | ||
| 166 | print "a is in the table" | ||
| 167 | |||
| 168 | not_exist = item not in list | ||
| 169 | |||
| 170 | check = -> value not in table | ||
| 171 | ``` | ||
| 172 | |||
| 173 | </YueDisplay> | ||
| 174 | |||
| 175 | A single-element list or table checks for equality with that element: | ||
| 176 | |||
| 177 | ```yuescript | ||
| 178 | -- [1,] checks if value == 1 | ||
| 179 | c = a in [1,] | ||
| 180 | |||
| 181 | -- {1} also checks if value == 1 | ||
| 182 | c = a in {1} | ||
| 183 | |||
| 184 | -- Without comma, [1] is indexing (tb[1]) | ||
| 185 | with tb | ||
| 186 | c = a in [1] | ||
| 187 | ``` | ||
| 188 | |||
| 189 | <YueDisplay> | ||
| 190 | |||
| 191 | ```yue | ||
| 192 | -- [1,] checks if value == 1 | ||
| 193 | c = a in [1,] | ||
| 194 | |||
| 195 | -- {1} also checks if value == 1 | ||
| 196 | c = a in {1} | ||
| 197 | |||
| 198 | -- Without comma, [1] is indexing (tb[1]) | ||
| 199 | with tb | ||
| 200 | c = a in [1] | ||
| 201 | ``` | ||
| 202 | |||
| 203 | </YueDisplay> | ||
diff --git a/doc/docs/doc/control-flow/goto.md b/doc/docs/doc/control-flow/goto.md new file mode 100644 index 0000000..00227ba --- /dev/null +++ b/doc/docs/doc/control-flow/goto.md | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | # Goto | ||
| 2 | |||
| 3 | YueScript supports goto statement and label syntax for controlling program flow, following the same rules as Lua's goto statement. **Note:** The goto statement requires Lua 5.2 or higher. When compiling to Lua 5.1, using goto syntax will result in a compilation error. | ||
| 4 | |||
| 5 | A label is defined using double colons: | ||
| 6 | |||
| 7 | ```yuescript | ||
| 8 | ::start:: | ||
| 9 | ::done:: | ||
| 10 | ::my_label:: | ||
| 11 | ``` | ||
| 12 | |||
| 13 | <YueDisplay> | ||
| 14 | |||
| 15 | ```yue | ||
| 16 | ::start:: | ||
| 17 | ::done:: | ||
| 18 | ::my_label:: | ||
| 19 | ``` | ||
| 20 | |||
| 21 | </YueDisplay> | ||
| 22 | |||
| 23 | The goto statement jumps to a specified label: | ||
| 24 | |||
| 25 | ```yuescript | ||
| 26 | a = 0 | ||
| 27 | ::start:: | ||
| 28 | a += 1 | ||
| 29 | goto done if a == 5 | ||
| 30 | goto start | ||
| 31 | ::done:: | ||
| 32 | print "a is now 5" | ||
| 33 | ``` | ||
| 34 | |||
| 35 | <YueDisplay> | ||
| 36 | |||
| 37 | ```yue | ||
| 38 | a = 0 | ||
| 39 | ::start:: | ||
| 40 | a += 1 | ||
| 41 | goto done if a == 5 | ||
| 42 | goto start | ||
| 43 | ::done:: | ||
| 44 | print "a is now 5" | ||
| 45 | ``` | ||
| 46 | |||
| 47 | </YueDisplay> | ||
| 48 | |||
| 49 | The goto statement is useful for breaking out of deeply nested loops: | ||
| 50 | |||
| 51 | ```yuescript | ||
| 52 | for z = 1, 10 | ||
| 53 | for y = 1, 10 do for x = 1, 10 | ||
| 54 | if x^2 + y^2 == z^2 | ||
| 55 | print 'found a Pythagorean triple:', x, y, z | ||
| 56 | goto ok | ||
| 57 | ::ok:: | ||
| 58 | ``` | ||
| 59 | |||
| 60 | <YueDisplay> | ||
| 61 | |||
| 62 | ```yue | ||
| 63 | for z = 1, 10 | ||
| 64 | for y = 1, 10 do for x = 1, 10 | ||
| 65 | if x^2 + y^2 == z^2 | ||
| 66 | print 'found a Pythagorean triple:', x, y, z | ||
| 67 | goto ok | ||
| 68 | ::ok:: | ||
| 69 | ``` | ||
| 70 | |||
| 71 | </YueDisplay> | ||
| 72 | |||
| 73 | You can also use labels to jump to a specific loop level: | ||
| 74 | |||
| 75 | ```yuescript | ||
| 76 | for z = 1, 10 | ||
| 77 | for y = 1, 10 | ||
| 78 | for x = 1, 10 | ||
| 79 | if x^2 + y^2 == z^2 | ||
| 80 | print 'found a Pythagorean triple:', x, y, z | ||
| 81 | print 'now trying next z...' | ||
| 82 | goto zcontinue | ||
| 83 | ::zcontinue:: | ||
| 84 | ``` | ||
| 85 | |||
| 86 | <YueDisplay> | ||
| 87 | |||
| 88 | ```yue | ||
| 89 | for z = 1, 10 | ||
| 90 | for y = 1, 10 | ||
| 91 | for x = 1, 10 | ||
| 92 | if x^2 + y^2 == z^2 | ||
| 93 | print 'found a Pythagorean triple:', x, y, z | ||
| 94 | print 'now trying next z...' | ||
| 95 | goto zcontinue | ||
| 96 | ::zcontinue:: | ||
| 97 | ``` | ||
| 98 | |||
| 99 | </YueDisplay> | ||
| 100 | |||
| 101 | ## Notes | ||
| 102 | |||
| 103 | - Labels must be unique within their scope | ||
| 104 | - goto can jump to labels at the same or outer scope levels | ||
| 105 | - goto cannot jump into inner scopes (like inside blocks or loops) | ||
| 106 | - Use goto sparingly, as it can make code harder to read and maintain | ||
diff --git a/doc/docs/id-id/doc/control-flow/conditionals.md b/doc/docs/id-id/doc/control-flow/conditionals.md index 861eae6..db67a79 100644 --- a/doc/docs/id-id/doc/control-flow/conditionals.md +++ b/doc/docs/id-id/doc/control-flow/conditionals.md | |||
| @@ -143,3 +143,61 @@ if a in list | |||
| 143 | ``` | 143 | ``` |
| 144 | 144 | ||
| 145 | </YueDisplay> | 145 | </YueDisplay> |
| 146 | |||
| 147 | Operator `in` juga dapat digunakan dengan tabel dan mendukung varian `not in` untuk negasi: | ||
| 148 | |||
| 149 | ```yuescript | ||
| 150 | has = "foo" in {"bar", "foo"} | ||
| 151 | |||
| 152 | if a in {1, 2, 3} | ||
| 153 | print "a ada di dalam tabel" | ||
| 154 | |||
| 155 | not_exist = item not in list | ||
| 156 | |||
| 157 | check = -> value not in table | ||
| 158 | ``` | ||
| 159 | |||
| 160 | <YueDisplay> | ||
| 161 | |||
| 162 | ```yue | ||
| 163 | has = "foo" in {"bar", "foo"} | ||
| 164 | |||
| 165 | if a in {1, 2, 3} | ||
| 166 | print "a ada di dalam tabel" | ||
| 167 | |||
| 168 | not_exist = item not in list | ||
| 169 | |||
| 170 | check = -> value not in table | ||
| 171 | ``` | ||
| 172 | |||
| 173 | </YueDisplay> | ||
| 174 | |||
| 175 | Daftar atau tabel dengan satu elemen memeriksa kesamaan dengan elemen tersebut: | ||
| 176 | |||
| 177 | ```yuescript | ||
| 178 | -- [1,] memeriksa apakah nilai == 1 | ||
| 179 | c = a in [1,] | ||
| 180 | |||
| 181 | -- {1} juga memeriksa apakah nilai == 1 | ||
| 182 | c = a in {1} | ||
| 183 | |||
| 184 | -- Tanpa koma, [1] adalah akses indeks (tb[1]) | ||
| 185 | with tb | ||
| 186 | c = a in [1] | ||
| 187 | ``` | ||
| 188 | |||
| 189 | <YueDisplay> | ||
| 190 | |||
| 191 | ```yue | ||
| 192 | -- [1,] memeriksa apakah nilai == 1 | ||
| 193 | c = a in [1,] | ||
| 194 | |||
| 195 | -- {1} juga memeriksa apakah nilai == 1 | ||
| 196 | c = a in {1} | ||
| 197 | |||
| 198 | -- Tanpa koma, [1] adalah akses indeks (tb[1]) | ||
| 199 | with tb | ||
| 200 | c = a in [1] | ||
| 201 | ``` | ||
| 202 | |||
| 203 | </YueDisplay> | ||
diff --git a/doc/docs/id-id/doc/control-flow/goto.md b/doc/docs/id-id/doc/control-flow/goto.md new file mode 100644 index 0000000..f387f0d --- /dev/null +++ b/doc/docs/id-id/doc/control-flow/goto.md | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | # Goto | ||
| 2 | |||
| 3 | YueScript mendukung pernyataan goto dan sintaks label untuk mengontrol alur program, mengikuti aturan yang sama dengan pernyataan goto Lua. **Catatan:** Pernyataan goto memerlukan Lua 5.2 atau lebih tinggi. Saat mengompilasi ke Lua 5.1, penggunaan sintaks goto akan menyebabkan galat kompilasi. | ||
| 4 | |||
| 5 | Label didefinisikan menggunakan dua titik dua: | ||
| 6 | |||
| 7 | ```yuescript | ||
| 8 | ::mulai:: | ||
| 9 | ::selesai:: | ||
| 10 | ::label_saya:: | ||
| 11 | ``` | ||
| 12 | |||
| 13 | <YueDisplay> | ||
| 14 | |||
| 15 | ```yue | ||
| 16 | ::mulai:: | ||
| 17 | ::selesai:: | ||
| 18 | ::label_saya:: | ||
| 19 | ``` | ||
| 20 | |||
| 21 | </YueDisplay> | ||
| 22 | |||
| 23 | Pernyataan goto melompat ke label yang ditentukan: | ||
| 24 | |||
| 25 | ```yuescript | ||
| 26 | a = 0 | ||
| 27 | ::mulai:: | ||
| 28 | a += 1 | ||
| 29 | goto selesai if a == 5 | ||
| 30 | goto mulai | ||
| 31 | ::selesai:: | ||
| 32 | print "a sekarang 5" | ||
| 33 | ``` | ||
| 34 | |||
| 35 | <YueDisplay> | ||
| 36 | |||
| 37 | ```yue | ||
| 38 | a = 0 | ||
| 39 | ::mulai:: | ||
| 40 | a += 1 | ||
| 41 | goto selesai if a == 5 | ||
| 42 | goto mulai | ||
| 43 | ::selesai:: | ||
| 44 | print "a sekarang 5" | ||
| 45 | ``` | ||
| 46 | |||
| 47 | </YueDisplay> | ||
| 48 | |||
| 49 | Pernyataan goto berguna untuk keluar dari loop yang bersarang dalam: | ||
| 50 | |||
| 51 | ```yuescript | ||
| 52 | for z = 1, 10 | ||
| 53 | for y = 1, 10 do for x = 1, 10 | ||
| 54 | if x^2 + y^2 == z^2 | ||
| 55 | print 'tripel Pythagorean ditemukan:', x, y, z | ||
| 56 | goto ok | ||
| 57 | ::ok:: | ||
| 58 | ``` | ||
| 59 | |||
| 60 | <YueDisplay> | ||
| 61 | |||
| 62 | ```yue | ||
| 63 | for z = 1, 10 | ||
| 64 | for y = 1, 10 do for x = 1, 10 | ||
| 65 | if x^2 + y^2 == z^2 | ||
| 66 | print 'tripel Pythagorean ditemukan:', x, y, z | ||
| 67 | goto ok | ||
| 68 | ::ok:: | ||
| 69 | ``` | ||
| 70 | |||
| 71 | </YueDisplay> | ||
| 72 | |||
| 73 | Anda juga dapat menggunakan label untuk melompat ke tingkat loop tertentu: | ||
| 74 | |||
| 75 | ```yuescript | ||
| 76 | for z = 1, 10 | ||
| 77 | for y = 1, 10 | ||
| 78 | for x = 1, 10 | ||
| 79 | if x^2 + y^2 == z^2 | ||
| 80 | print 'tripel Pythagorean ditemukan:', x, y, z | ||
| 81 | print 'mencoba z berikutnya...' | ||
| 82 | goto zcontinue | ||
| 83 | ::zcontinue:: | ||
| 84 | ``` | ||
| 85 | |||
| 86 | <YueDisplay> | ||
| 87 | |||
| 88 | ```yue | ||
| 89 | for z = 1, 10 | ||
| 90 | for y = 1, 10 | ||
| 91 | for x = 1, 10 | ||
| 92 | if x^2 + y^2 == z^2 | ||
| 93 | print 'tripel Pythagorean ditemukan:', x, y, z | ||
| 94 | print 'mencoba z berikutnya...' | ||
| 95 | goto zcontinue | ||
| 96 | ::zcontinue:: | ||
| 97 | ``` | ||
| 98 | |||
| 99 | </YueDisplay> | ||
| 100 | |||
| 101 | ## Catatan | ||
| 102 | |||
| 103 | - Label harus unik dalam cakupannya | ||
| 104 | - goto dapat melompat ke label pada tingkat cakupan yang sama atau luar | ||
| 105 | - goto tidak dapat melompat ke cakupan dalam (seperti di dalam blok atau loop) | ||
| 106 | - Gunakan goto dengan hemat, karena dapat membuat kode lebih sulit dibaca dan dipelihara | ||
diff --git a/doc/docs/pt-br/doc/control-flow/conditionals.md b/doc/docs/pt-br/doc/control-flow/conditionals.md index bc12d4e..ce32d89 100644 --- a/doc/docs/pt-br/doc/control-flow/conditionals.md +++ b/doc/docs/pt-br/doc/control-flow/conditionals.md | |||
| @@ -143,3 +143,61 @@ if a in list | |||
| 143 | ``` | 143 | ``` |
| 144 | 144 | ||
| 145 | </YueDisplay> | 145 | </YueDisplay> |
| 146 | |||
| 147 | O operador `in` também pode ser usado com tabelas e suporta a variante `not in` para negação: | ||
| 148 | |||
| 149 | ```yuescript | ||
| 150 | has = "foo" in {"bar", "foo"} | ||
| 151 | |||
| 152 | if a in {1, 2, 3} | ||
| 153 | print "a está na tabela" | ||
| 154 | |||
| 155 | not_exist = item not in list | ||
| 156 | |||
| 157 | check = -> value not in table | ||
| 158 | ``` | ||
| 159 | |||
| 160 | <YueDisplay> | ||
| 161 | |||
| 162 | ```yue | ||
| 163 | has = "foo" in {"bar", "foo"} | ||
| 164 | |||
| 165 | if a in {1, 2, 3} | ||
| 166 | print "a está na tabela" | ||
| 167 | |||
| 168 | not_exist = item not in list | ||
| 169 | |||
| 170 | check = -> value not in table | ||
| 171 | ``` | ||
| 172 | |||
| 173 | </YueDisplay> | ||
| 174 | |||
| 175 | Uma lista ou tabela de único elemento verifica igualdade com esse elemento: | ||
| 176 | |||
| 177 | ```yuescript | ||
| 178 | -- [1,] verifica se valor == 1 | ||
| 179 | c = a in [1,] | ||
| 180 | |||
| 181 | -- {1} também verifica se valor == 1 | ||
| 182 | c = a in {1} | ||
| 183 | |||
| 184 | -- Sem vírgula, [1] é acesso por índice (tb[1]) | ||
| 185 | with tb | ||
| 186 | c = a in [1] | ||
| 187 | ``` | ||
| 188 | |||
| 189 | <YueDisplay> | ||
| 190 | |||
| 191 | ```yue | ||
| 192 | -- [1,] verifica se valor == 1 | ||
| 193 | c = a in [1,] | ||
| 194 | |||
| 195 | -- {1} também verifica se valor == 1 | ||
| 196 | c = a in {1} | ||
| 197 | |||
| 198 | -- Sem vírgula, [1] é acesso por índice (tb[1]) | ||
| 199 | with tb | ||
| 200 | c = a in [1] | ||
| 201 | ``` | ||
| 202 | |||
| 203 | </YueDisplay> | ||
diff --git a/doc/docs/pt-br/doc/control-flow/goto.md b/doc/docs/pt-br/doc/control-flow/goto.md new file mode 100644 index 0000000..f4c85f4 --- /dev/null +++ b/doc/docs/pt-br/doc/control-flow/goto.md | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | # Goto | ||
| 2 | |||
| 3 | YueScript suporta a instrução goto e a sintaxe de rótulos para controlar o fluxo do programa, seguindo as mesmas regras da instrução goto do Lua. **Nota:** A instrução goto requer Lua 5.2 ou superior. Ao compilar para Lua 5.1, o uso da sintaxe goto resultará em um erro de compilação. | ||
| 4 | |||
| 5 | Um rótulo é definido usando dois pontos duplos: | ||
| 6 | |||
| 7 | ```yuescript | ||
| 8 | ::inicio:: | ||
| 9 | ::fim:: | ||
| 10 | ::meu_rotulo:: | ||
| 11 | ``` | ||
| 12 | |||
| 13 | <YueDisplay> | ||
| 14 | |||
| 15 | ```yue | ||
| 16 | ::inicio:: | ||
| 17 | ::fim:: | ||
| 18 | ::meu_rotulo:: | ||
| 19 | ``` | ||
| 20 | |||
| 21 | </YueDisplay> | ||
| 22 | |||
| 23 | A instrução goto salta para um rótulo especificado: | ||
| 24 | |||
| 25 | ```yuescript | ||
| 26 | a = 0 | ||
| 27 | ::inicio:: | ||
| 28 | a += 1 | ||
| 29 | goto fim if a == 5 | ||
| 30 | goto inicio | ||
| 31 | ::fim:: | ||
| 32 | print "a agora é 5" | ||
| 33 | ``` | ||
| 34 | |||
| 35 | <YueDisplay> | ||
| 36 | |||
| 37 | ```yue | ||
| 38 | a = 0 | ||
| 39 | ::inicio:: | ||
| 40 | a += 1 | ||
| 41 | goto fim if a == 5 | ||
| 42 | goto inicio | ||
| 43 | ::fim:: | ||
| 44 | print "a agora é 5" | ||
| 45 | ``` | ||
| 46 | |||
| 47 | </YueDisplay> | ||
| 48 | |||
| 49 | A instrução goto é útil para sair de laços profundamente aninhados: | ||
| 50 | |||
| 51 | ```yuescript | ||
| 52 | for z = 1, 10 | ||
| 53 | for y = 1, 10 do for x = 1, 10 | ||
| 54 | if x^2 + y^2 == z^2 | ||
| 55 | print 'triplo pitagórico encontrado:', x, y, z | ||
| 56 | goto ok | ||
| 57 | ::ok:: | ||
| 58 | ``` | ||
| 59 | |||
| 60 | <YueDisplay> | ||
| 61 | |||
| 62 | ```yue | ||
| 63 | for z = 1, 10 | ||
| 64 | for y = 1, 10 do for x = 1, 10 | ||
| 65 | if x^2 + y^2 == z^2 | ||
| 66 | print 'triplo pitagórico encontrado:', x, y, z | ||
| 67 | goto ok | ||
| 68 | ::ok:: | ||
| 69 | ``` | ||
| 70 | |||
| 71 | </YueDisplay> | ||
| 72 | |||
| 73 | Você também pode usar rótulos para pular para um nível específico de laço: | ||
| 74 | |||
| 75 | ```yuescript | ||
| 76 | for z = 1, 10 | ||
| 77 | for y = 1, 10 | ||
| 78 | for x = 1, 10 | ||
| 79 | if x^2 + y^2 == z^2 | ||
| 80 | print 'triplo pitagórico encontrado:', x, y, z | ||
| 81 | print 'tentando próximo z...' | ||
| 82 | goto zcontinue | ||
| 83 | ::zcontinue:: | ||
| 84 | ``` | ||
| 85 | |||
| 86 | <YueDisplay> | ||
| 87 | |||
| 88 | ```yue | ||
| 89 | for z = 1, 10 | ||
| 90 | for y = 1, 10 | ||
| 91 | for x = 1, 10 | ||
| 92 | if x^2 + y^2 == z^2 | ||
| 93 | print 'triplo pitagórico encontrado:', x, y, z | ||
| 94 | print 'tentando próximo z...' | ||
| 95 | goto zcontinue | ||
| 96 | ::zcontinue:: | ||
| 97 | ``` | ||
| 98 | |||
| 99 | </YueDisplay> | ||
| 100 | |||
| 101 | ## Notas | ||
| 102 | |||
| 103 | - Rótulos devem ser únicos dentro de seu escopo | ||
| 104 | - goto pode pular para rótulos nos mesmos níveis de escopo ou externos | ||
| 105 | - goto não pode pular para escopos internos (como dentro de blocos ou laços) | ||
| 106 | - Use goto com moderação, pois pode tornar o código mais difícil de ler e manter | ||
diff --git a/doc/docs/zh/doc/control-flow/conditionals.md b/doc/docs/zh/doc/control-flow/conditionals.md index 3a4d5d1..f8d2851 100644 --- a/doc/docs/zh/doc/control-flow/conditionals.md +++ b/doc/docs/zh/doc/control-flow/conditionals.md | |||
| @@ -143,3 +143,61 @@ if a in list | |||
| 143 | ``` | 143 | ``` |
| 144 | 144 | ||
| 145 | </YueDisplay> | 145 | </YueDisplay> |
| 146 | |||
| 147 | `in` 运算符也可以用于表,并支持 `not in` 变体来进行否定检查: | ||
| 148 | |||
| 149 | ```yuescript | ||
| 150 | has = "foo" in {"bar", "foo"} | ||
| 151 | |||
| 152 | if a in {1, 2, 3} | ||
| 153 | print "a 在表中" | ||
| 154 | |||
| 155 | not_exist = item not in list | ||
| 156 | |||
| 157 | check = -> value not in table | ||
| 158 | ``` | ||
| 159 | |||
| 160 | <YueDisplay> | ||
| 161 | |||
| 162 | ```yue | ||
| 163 | has = "foo" in {"bar", "foo"} | ||
| 164 | |||
| 165 | if a in {1, 2, 3} | ||
| 166 | print "a 在表中" | ||
| 167 | |||
| 168 | not_exist = item not in list | ||
| 169 | |||
| 170 | check = -> value not in table | ||
| 171 | ``` | ||
| 172 | |||
| 173 | </YueDisplay> | ||
| 174 | |||
| 175 | 单元素列表或表会检查与该元素的相等性: | ||
| 176 | |||
| 177 | ```yuescript | ||
| 178 | -- [1,] 检查 value == 1 | ||
| 179 | c = a in [1,] | ||
| 180 | |||
| 181 | -- {1} 也是检查 value == 1 | ||
| 182 | c = a in {1} | ||
| 183 | |||
| 184 | -- 没有逗号,[1] 是索引访问(tb[1]) | ||
| 185 | with tb | ||
| 186 | c = a in [1] | ||
| 187 | ``` | ||
| 188 | |||
| 189 | <YueDisplay> | ||
| 190 | |||
| 191 | ```yue | ||
| 192 | -- [1,] 检查 value == 1 | ||
| 193 | c = a in [1,] | ||
| 194 | |||
| 195 | -- {1} 也是检查 value == 1 | ||
| 196 | c = a in {1} | ||
| 197 | |||
| 198 | -- 没有逗号,[1] 是索引访问(tb[1]) | ||
| 199 | with tb | ||
| 200 | c = a in [1] | ||
| 201 | ``` | ||
| 202 | |||
| 203 | </YueDisplay> | ||
diff --git a/doc/docs/zh/doc/control-flow/goto.md b/doc/docs/zh/doc/control-flow/goto.md new file mode 100644 index 0000000..6d1cc89 --- /dev/null +++ b/doc/docs/zh/doc/control-flow/goto.md | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | # Goto | ||
| 2 | |||
| 3 | YueScript 支持 goto 语句和标签语法来控制程序流程,该语法遵循与 Lua 的 goto 语句相同的规则。**注意:** goto 语句需要 Lua 5.2 或更高版本。当编译目标是 Lua 5.1 时,使用 goto 语法将导致编译错误。 | ||
| 4 | |||
| 5 | 标签使用双冒号定义: | ||
| 6 | |||
| 7 | ```yuescript | ||
| 8 | ::开始:: | ||
| 9 | ::结束:: | ||
| 10 | ::我的标签:: | ||
| 11 | ``` | ||
| 12 | |||
| 13 | <YueDisplay> | ||
| 14 | |||
| 15 | ```yue | ||
| 16 | ::开始:: | ||
| 17 | ::结束:: | ||
| 18 | ::我的标签:: | ||
| 19 | ``` | ||
| 20 | |||
| 21 | </YueDisplay> | ||
| 22 | |||
| 23 | goto 语句可以跳转到指定的标签: | ||
| 24 | |||
| 25 | ```yuescript | ||
| 26 | a = 0 | ||
| 27 | ::开始:: | ||
| 28 | a += 1 | ||
| 29 | goto 结束 if a == 5 | ||
| 30 | goto 开始 | ||
| 31 | ::结束:: | ||
| 32 | print "a 现在是 5" | ||
| 33 | ``` | ||
| 34 | |||
| 35 | <YueDisplay> | ||
| 36 | |||
| 37 | ```yue | ||
| 38 | a = 0 | ||
| 39 | ::开始:: | ||
| 40 | a += 1 | ||
| 41 | goto 结束 if a == 5 | ||
| 42 | goto 开始 | ||
| 43 | ::结束:: | ||
| 44 | print "a 现在是 5" | ||
| 45 | ``` | ||
| 46 | |||
| 47 | </YueDisplay> | ||
| 48 | |||
| 49 | goto 语句对于跳出深层嵌套循环非常有用: | ||
| 50 | |||
| 51 | ```yuescript | ||
| 52 | for z = 1, 10 | ||
| 53 | for y = 1, 10 do for x = 1, 10 | ||
| 54 | if x^2 + y^2 == z^2 | ||
| 55 | print '找到勾股数:', x, y, z | ||
| 56 | goto 完成 | ||
| 57 | ::完成:: | ||
| 58 | ``` | ||
| 59 | |||
| 60 | <YueDisplay> | ||
| 61 | |||
| 62 | ```yue | ||
| 63 | for z = 1, 10 | ||
| 64 | for y = 1, 10 do for x = 1, 10 | ||
| 65 | if x^2 + y^2 == z^2 | ||
| 66 | print '找到勾股数:', x, y, z | ||
| 67 | goto 完成 | ||
| 68 | ::完成:: | ||
| 69 | ``` | ||
| 70 | |||
| 71 | </YueDisplay> | ||
| 72 | |||
| 73 | 你也可以使用标签跳转到特定的循环层级: | ||
| 74 | |||
| 75 | ```yuescript | ||
| 76 | for z = 1, 10 | ||
| 77 | for y = 1, 10 | ||
| 78 | for x = 1, 10 | ||
| 79 | if x^2 + y^2 == z^2 | ||
| 80 | print '找到勾股数:', x, y, z | ||
| 81 | print '尝试下一个 z...' | ||
| 82 | goto 继续z | ||
| 83 | ::继续z:: | ||
| 84 | ``` | ||
| 85 | |||
| 86 | <YueDisplay> | ||
| 87 | |||
| 88 | ```yue | ||
| 89 | for z = 1, 10 | ||
| 90 | for y = 1, 10 | ||
| 91 | for x = 1, 10 | ||
| 92 | if x^2 + y^2 == z^2 | ||
| 93 | print '找到勾股数:', x, y, z | ||
| 94 | print '尝试下一个 z...' | ||
| 95 | goto 继续z | ||
| 96 | ::继续z:: | ||
| 97 | ``` | ||
| 98 | |||
| 99 | </YueDisplay> | ||
| 100 | |||
| 101 | ## 注意事项 | ||
| 102 | |||
| 103 | - 标签在其作用域内必须唯一 | ||
| 104 | - goto 可以跳转到相同或外层作用域级别的标签 | ||
| 105 | - goto 不能跳转到内层作用域(如代码块或循环内部) | ||
| 106 | - 谨慎使用 goto,因为它会使代码更难阅读和维护 | ||
diff --git a/doc/yue-de.md b/doc/yue-de.md index 9149231..1a13a47 100644 --- a/doc/yue-de.md +++ b/doc/yue-de.md | |||
| @@ -2779,6 +2779,64 @@ if a in list | |||
| 2779 | 2779 | ||
| 2780 | </YueDisplay> | 2780 | </YueDisplay> |
| 2781 | 2781 | ||
| 2782 | Der `in`-Operator kann auch mit Tabellen verwendet werden und unterstützt die Variante `not in` für Verneinungen: | ||
| 2783 | |||
| 2784 | ```yuescript | ||
| 2785 | has = "foo" in {"bar", "foo"} | ||
| 2786 | |||
| 2787 | if a in {1, 2, 3} | ||
| 2788 | print "a ist in der Tabelle" | ||
| 2789 | |||
| 2790 | not_exist = item not in list | ||
| 2791 | |||
| 2792 | check = -> value not in table | ||
| 2793 | ``` | ||
| 2794 | |||
| 2795 | <YueDisplay> | ||
| 2796 | |||
| 2797 | ```yue | ||
| 2798 | has = "foo" in {"bar", "foo"} | ||
| 2799 | |||
| 2800 | if a in {1, 2, 3} | ||
| 2801 | print "a ist in der Tabelle" | ||
| 2802 | |||
| 2803 | not_exist = item not in list | ||
| 2804 | |||
| 2805 | check = -> value not in table | ||
| 2806 | ``` | ||
| 2807 | |||
| 2808 | </YueDisplay> | ||
| 2809 | |||
| 2810 | Eine Ein-Element-Liste oder Tabelle prüft auf Gleichheit mit diesem Element: | ||
| 2811 | |||
| 2812 | ```yuescript | ||
| 2813 | -- [1,] prüft, ob wert == 1 | ||
| 2814 | c = a in [1,] | ||
| 2815 | |||
| 2816 | -- {1} prüft auch, ob wert == 1 | ||
| 2817 | c = a in {1} | ||
| 2818 | |||
| 2819 | -- Ohne Komma ist [1] ein Indexzugriff (tb[1]) | ||
| 2820 | with tb | ||
| 2821 | c = a in [1] | ||
| 2822 | ``` | ||
| 2823 | |||
| 2824 | <YueDisplay> | ||
| 2825 | |||
| 2826 | ```yue | ||
| 2827 | -- [1,] prüft, ob wert == 1 | ||
| 2828 | c = a in [1,] | ||
| 2829 | |||
| 2830 | -- {1} prüft auch, ob wert == 1 | ||
| 2831 | c = a in {1} | ||
| 2832 | |||
| 2833 | -- Ohne Komma ist [1] ein Indexzugriff (tb[1]) | ||
| 2834 | with tb | ||
| 2835 | c = a in [1] | ||
| 2836 | ``` | ||
| 2837 | |||
| 2838 | </YueDisplay> | ||
| 2839 | |||
| 2782 | # For-Schleife | 2840 | # For-Schleife |
| 2783 | 2841 | ||
| 2784 | Es gibt zwei Formen der `for`-Schleife, genau wie in Lua: eine numerische und eine generische. | 2842 | Es gibt zwei Formen der `for`-Schleife, genau wie in Lua: eine numerische und eine generische. |
diff --git a/doc/yue-en.md b/doc/yue-en.md index a3d98d3..3f8546a 100644 --- a/doc/yue-en.md +++ b/doc/yue-en.md | |||
| @@ -2780,6 +2780,64 @@ if a in list | |||
| 2780 | 2780 | ||
| 2781 | </YueDisplay> | 2781 | </YueDisplay> |
| 2782 | 2782 | ||
| 2783 | The `in` operator can also be used with tables and supports the `not in` variant for negation: | ||
| 2784 | |||
| 2785 | ```yuescript | ||
| 2786 | has = "foo" in {"bar", "foo"} | ||
| 2787 | |||
| 2788 | if a in {1, 2, 3} | ||
| 2789 | print "a is in the table" | ||
| 2790 | |||
| 2791 | not_exist = item not in list | ||
| 2792 | |||
| 2793 | check = -> value not in table | ||
| 2794 | ``` | ||
| 2795 | |||
| 2796 | <YueDisplay> | ||
| 2797 | |||
| 2798 | ```yue | ||
| 2799 | has = "foo" in {"bar", "foo"} | ||
| 2800 | |||
| 2801 | if a in {1, 2, 3} | ||
| 2802 | print "a is in the table" | ||
| 2803 | |||
| 2804 | not_exist = item not in list | ||
| 2805 | |||
| 2806 | check = -> value not in table | ||
| 2807 | ``` | ||
| 2808 | |||
| 2809 | </YueDisplay> | ||
| 2810 | |||
| 2811 | A single-element list or table checks for equality with that element: | ||
| 2812 | |||
| 2813 | ```yuescript | ||
| 2814 | -- [1,] checks if value == 1 | ||
| 2815 | c = a in [1,] | ||
| 2816 | |||
| 2817 | -- {1} also checks if value == 1 | ||
| 2818 | c = a in {1} | ||
| 2819 | |||
| 2820 | -- Without comma, [1] is indexing (tb[1]) | ||
| 2821 | with tb | ||
| 2822 | c = a in [1] | ||
| 2823 | ``` | ||
| 2824 | |||
| 2825 | <YueDisplay> | ||
| 2826 | |||
| 2827 | ```yue | ||
| 2828 | -- [1,] checks if value == 1 | ||
| 2829 | c = a in [1,] | ||
| 2830 | |||
| 2831 | -- {1} also checks if value == 1 | ||
| 2832 | c = a in {1} | ||
| 2833 | |||
| 2834 | -- Without comma, [1] is indexing (tb[1]) | ||
| 2835 | with tb | ||
| 2836 | c = a in [1] | ||
| 2837 | ``` | ||
| 2838 | |||
| 2839 | </YueDisplay> | ||
| 2840 | |||
| 2783 | # For Loop | 2841 | # For Loop |
| 2784 | 2842 | ||
| 2785 | There are two for loop forms, just like in Lua. A numeric one and a generic one: | 2843 | There are two for loop forms, just like in Lua. A numeric one and a generic one: |
diff --git a/doc/yue-id-id.md b/doc/yue-id-id.md index 365ee32..ca90d85 100644 --- a/doc/yue-id-id.md +++ b/doc/yue-id-id.md | |||
| @@ -2778,6 +2778,64 @@ if a in list | |||
| 2778 | 2778 | ||
| 2779 | </YueDisplay> | 2779 | </YueDisplay> |
| 2780 | 2780 | ||
| 2781 | Operator `in` juga dapat digunakan dengan tabel dan mendukung varian `not in` untuk negasi: | ||
| 2782 | |||
| 2783 | ```yuescript | ||
| 2784 | has = "foo" in {"bar", "foo"} | ||
| 2785 | |||
| 2786 | if a in {1, 2, 3} | ||
| 2787 | print "a ada di dalam tabel" | ||
| 2788 | |||
| 2789 | not_exist = item not in list | ||
| 2790 | |||
| 2791 | check = -> value not in table | ||
| 2792 | ``` | ||
| 2793 | |||
| 2794 | <YueDisplay> | ||
| 2795 | |||
| 2796 | ```yue | ||
| 2797 | has = "foo" in {"bar", "foo"} | ||
| 2798 | |||
| 2799 | if a in {1, 2, 3} | ||
| 2800 | print "a ada di dalam tabel" | ||
| 2801 | |||
| 2802 | not_exist = item not in list | ||
| 2803 | |||
| 2804 | check = -> value not in table | ||
| 2805 | ``` | ||
| 2806 | |||
| 2807 | </YueDisplay> | ||
| 2808 | |||
| 2809 | Daftar atau tabel dengan satu elemen memeriksa kesamaan dengan elemen tersebut: | ||
| 2810 | |||
| 2811 | ```yuescript | ||
| 2812 | -- [1,] memeriksa apakah nilai == 1 | ||
| 2813 | c = a in [1,] | ||
| 2814 | |||
| 2815 | -- {1} juga memeriksa apakah nilai == 1 | ||
| 2816 | c = a in {1} | ||
| 2817 | |||
| 2818 | -- Tanpa koma, [1] adalah akses indeks (tb[1]) | ||
| 2819 | with tb | ||
| 2820 | c = a in [1] | ||
| 2821 | ``` | ||
| 2822 | |||
| 2823 | <YueDisplay> | ||
| 2824 | |||
| 2825 | ```yue | ||
| 2826 | -- [1,] memeriksa apakah nilai == 1 | ||
| 2827 | c = a in [1,] | ||
| 2828 | |||
| 2829 | -- {1} juga memeriksa apakah nilai == 1 | ||
| 2830 | c = a in {1} | ||
| 2831 | |||
| 2832 | -- Tanpa koma, [1] adalah akses indeks (tb[1]) | ||
| 2833 | with tb | ||
| 2834 | c = a in [1] | ||
| 2835 | ``` | ||
| 2836 | |||
| 2837 | </YueDisplay> | ||
| 2838 | |||
| 2781 | # Perulangan For | 2839 | # Perulangan For |
| 2782 | 2840 | ||
| 2783 | Ada dua bentuk perulangan for, seperti di Lua. Satu numerik dan satu generik: | 2841 | Ada dua bentuk perulangan for, seperti di Lua. Satu numerik dan satu generik: |
diff --git a/doc/yue-pt-br.md b/doc/yue-pt-br.md index ad0521a..7bab231 100644 --- a/doc/yue-pt-br.md +++ b/doc/yue-pt-br.md | |||
| @@ -2777,6 +2777,64 @@ if a in list | |||
| 2777 | 2777 | ||
| 2778 | </YueDisplay> | 2778 | </YueDisplay> |
| 2779 | 2779 | ||
| 2780 | O operador `in` também pode ser usado com tabelas e suporta a variante `not in` para negação: | ||
| 2781 | |||
| 2782 | ```yuescript | ||
| 2783 | has = "foo" in {"bar", "foo"} | ||
| 2784 | |||
| 2785 | if a in {1, 2, 3} | ||
| 2786 | print "a está na tabela" | ||
| 2787 | |||
| 2788 | not_exist = item not in list | ||
| 2789 | |||
| 2790 | check = -> value not in table | ||
| 2791 | ``` | ||
| 2792 | |||
| 2793 | <YueDisplay> | ||
| 2794 | |||
| 2795 | ```yue | ||
| 2796 | has = "foo" in {"bar", "foo"} | ||
| 2797 | |||
| 2798 | if a in {1, 2, 3} | ||
| 2799 | print "a está na tabela" | ||
| 2800 | |||
| 2801 | not_exist = item not in list | ||
| 2802 | |||
| 2803 | check = -> value not in table | ||
| 2804 | ``` | ||
| 2805 | |||
| 2806 | </YueDisplay> | ||
| 2807 | |||
| 2808 | Uma lista ou tabela de único elemento verifica igualdade com esse elemento: | ||
| 2809 | |||
| 2810 | ```yuescript | ||
| 2811 | -- [1,] verifica se valor == 1 | ||
| 2812 | c = a in [1,] | ||
| 2813 | |||
| 2814 | -- {1} também verifica se valor == 1 | ||
| 2815 | c = a in {1} | ||
| 2816 | |||
| 2817 | -- Sem vírgula, [1] é acesso por índice (tb[1]) | ||
| 2818 | with tb | ||
| 2819 | c = a in [1] | ||
| 2820 | ``` | ||
| 2821 | |||
| 2822 | <YueDisplay> | ||
| 2823 | |||
| 2824 | ```yue | ||
| 2825 | -- [1,] verifica se valor == 1 | ||
| 2826 | c = a in [1,] | ||
| 2827 | |||
| 2828 | -- {1} também verifica se valor == 1 | ||
| 2829 | c = a in {1} | ||
| 2830 | |||
| 2831 | -- Sem vírgula, [1] é acesso por índice (tb[1]) | ||
| 2832 | with tb | ||
| 2833 | c = a in [1] | ||
| 2834 | ``` | ||
| 2835 | |||
| 2836 | </YueDisplay> | ||
| 2837 | |||
| 2780 | # Loop For | 2838 | # Loop For |
| 2781 | 2839 | ||
| 2782 | Existem duas formas de loop for, assim como no Lua. Uma numérica e uma genérica: | 2840 | Existem duas formas de loop for, assim como no Lua. Uma numérica e uma genérica: |
diff --git a/doc/yue-zh.md b/doc/yue-zh.md index d026fc2..93e21d8 100644 --- a/doc/yue-zh.md +++ b/doc/yue-zh.md | |||
| @@ -2770,6 +2770,64 @@ if a in list | |||
| 2770 | 2770 | ||
| 2771 | </YueDisplay> | 2771 | </YueDisplay> |
| 2772 | 2772 | ||
| 2773 | `in` 运算符也可以用于表,并支持 `not in` 变体来进行否定检查: | ||
| 2774 | |||
| 2775 | ```yuescript | ||
| 2776 | has = "foo" in {"bar", "foo"} | ||
| 2777 | |||
| 2778 | if a in {1, 2, 3} | ||
| 2779 | print "a 在表中" | ||
| 2780 | |||
| 2781 | not_exist = item not in list | ||
| 2782 | |||
| 2783 | check = -> value not in table | ||
| 2784 | ``` | ||
| 2785 | |||
| 2786 | <YueDisplay> | ||
| 2787 | |||
| 2788 | ```yue | ||
| 2789 | has = "foo" in {"bar", "foo"} | ||
| 2790 | |||
| 2791 | if a in {1, 2, 3} | ||
| 2792 | print "a 在表中" | ||
| 2793 | |||
| 2794 | not_exist = item not in list | ||
| 2795 | |||
| 2796 | check = -> value not in table | ||
| 2797 | ``` | ||
| 2798 | |||
| 2799 | </YueDisplay> | ||
| 2800 | |||
| 2801 | 单元素列表或表会检查与该元素的相等性: | ||
| 2802 | |||
| 2803 | ```yuescript | ||
| 2804 | -- [1,] 检查 value == 1 | ||
| 2805 | c = a in [1,] | ||
| 2806 | |||
| 2807 | -- {1} 也是检查 value == 1 | ||
| 2808 | c = a in {1} | ||
| 2809 | |||
| 2810 | -- 没有逗号,[1] 是索引访问(tb[1]) | ||
| 2811 | with tb | ||
| 2812 | c = a in [1] | ||
| 2813 | ``` | ||
| 2814 | |||
| 2815 | <YueDisplay> | ||
| 2816 | |||
| 2817 | ```yue | ||
| 2818 | -- [1,] 检查 value == 1 | ||
| 2819 | c = a in [1,] | ||
| 2820 | |||
| 2821 | -- {1} 也是检查 value == 1 | ||
| 2822 | c = a in {1} | ||
| 2823 | |||
| 2824 | -- 没有逗号,[1] 是索引访问(tb[1]) | ||
| 2825 | with tb | ||
| 2826 | c = a in [1] | ||
| 2827 | ``` | ||
| 2828 | |||
| 2829 | </YueDisplay> | ||
| 2830 | |||
| 2773 | # for 循环 | 2831 | # for 循环 |
| 2774 | 2832 | ||
| 2775 |   Lua 中有两种 for 循环形式,数字型和通用型: | 2833 |   Lua 中有两种 for 循环形式,数字型和通用型: |
