From cf5b1b4a68d762e6e33cac8367611ecea15fa942 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Sun, 15 Feb 2026 05:49:13 +0000 Subject: Add goto statement documentation and tests - 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 --- doc/docs/de/doc/control-flow/conditionals.md | 58 +++++++++++++++ doc/docs/de/doc/control-flow/goto.md | 106 +++++++++++++++++++++++++++ 2 files changed, 164 insertions(+) create mode 100644 doc/docs/de/doc/control-flow/goto.md (limited to 'doc/docs/de') 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 ``` + +Der `in`-Operator kann auch mit Tabellen verwendet werden und unterstützt die Variante `not in` für Verneinungen: + +```yuescript +has = "foo" in {"bar", "foo"} + +if a in {1, 2, 3} + print "a ist in der Tabelle" + +not_exist = item not in list + +check = -> value not in table +``` + + + +```yue +has = "foo" in {"bar", "foo"} + +if a in {1, 2, 3} + print "a ist in der Tabelle" + +not_exist = item not in list + +check = -> value not in table +``` + + + +Eine Ein-Element-Liste oder Tabelle prüft auf Gleichheit mit diesem Element: + +```yuescript +-- [1,] prüft, ob wert == 1 +c = a in [1,] + +-- {1} prüft auch, ob wert == 1 +c = a in {1} + +-- Ohne Komma ist [1] ein Indexzugriff (tb[1]) +with tb + c = a in [1] +``` + + + +```yue +-- [1,] prüft, ob wert == 1 +c = a in [1,] + +-- {1} prüft auch, ob wert == 1 +c = a in {1} + +-- Ohne Komma ist [1] ein Indexzugriff (tb[1]) +with tb + c = a in [1] +``` + + 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 @@ +# Goto + +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. + +Ein Label wird mit doppelten Doppelpunkten definiert: + +```yuescript +::start:: +::done:: +::mein_label:: +``` + + + +```yue +::start:: +::done:: +::mein_label:: +``` + + + +Die goto-Anweisung springt zu einem angegebenen Label: + +```yuescript +a = 0 +::start:: +a += 1 +goto done if a == 5 +goto start +::done:: +print "a ist jetzt 5" +``` + + + +```yue +a = 0 +::start:: +a += 1 +goto done if a == 5 +goto start +::done:: +print "a ist jetzt 5" +``` + + + +Die goto-Anweisung ist nützlich, um aus tief verschachtelten Schleifen zu springen: + +```yuescript +for z = 1, 10 + for y = 1, 10 do for x = 1, 10 + if x^2 + y^2 == z^2 + print 'Pythagoreisches Tripel gefunden:', x, y, z + goto ok +::ok:: +``` + + + +```yue +for z = 1, 10 + for y = 1, 10 do for x = 1, 10 + if x^2 + y^2 == z^2 + print 'Pythagoreisches Tripel gefunden:', x, y, z + goto ok +::ok:: +``` + + + +Sie können auch Labels verwenden, um zu einer bestimmten Schleifenebene zu springen: + +```yuescript +for z = 1, 10 + for y = 1, 10 + for x = 1, 10 + if x^2 + y^2 == z^2 + print 'Pythagoreisches Tripel gefunden:', x, y, z + print 'versuche nächstes z...' + goto zcontinue + ::zcontinue:: +``` + + + +```yue +for z = 1, 10 + for y = 1, 10 + for x = 1, 10 + if x^2 + y^2 == z^2 + print 'Pythagoreisches Tripel gefunden:', x, y, z + print 'versuche nächstes z...' + goto zcontinue + ::zcontinue:: +``` + + + +## Hinweise + +- Labels müssen innerhalb ihres Geltungsbereichs eindeutig sein +- goto kann zu Labels auf derselben oder äußeren Geltungsbereichsebenen springen +- goto kann nicht in innere Geltungsbereiche springen (wie in Blöcke oder Schleifen) +- Verwenden Sie goto sparsam, da es den Code schwieriger zu lesen und zu warten machen kann -- cgit v1.2.3-55-g6feb