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/id-id/doc/control-flow/conditionals.md | 58 +++++++++++++ doc/docs/id-id/doc/control-flow/goto.md | 106 ++++++++++++++++++++++++ 2 files changed, 164 insertions(+) create mode 100644 doc/docs/id-id/doc/control-flow/goto.md (limited to 'doc/docs/id-id') 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 ``` + +Operator `in` juga dapat digunakan dengan tabel dan mendukung varian `not in` untuk negasi: + +```yuescript +has = "foo" in {"bar", "foo"} + +if a in {1, 2, 3} + print "a ada di dalam tabel" + +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 ada di dalam tabel" + +not_exist = item not in list + +check = -> value not in table +``` + + + +Daftar atau tabel dengan satu elemen memeriksa kesamaan dengan elemen tersebut: + +```yuescript +-- [1,] memeriksa apakah nilai == 1 +c = a in [1,] + +-- {1} juga memeriksa apakah nilai == 1 +c = a in {1} + +-- Tanpa koma, [1] adalah akses indeks (tb[1]) +with tb + c = a in [1] +``` + + + +```yue +-- [1,] memeriksa apakah nilai == 1 +c = a in [1,] + +-- {1} juga memeriksa apakah nilai == 1 +c = a in {1} + +-- Tanpa koma, [1] adalah akses indeks (tb[1]) +with tb + c = a in [1] +``` + + 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 @@ +# Goto + +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. + +Label didefinisikan menggunakan dua titik dua: + +```yuescript +::mulai:: +::selesai:: +::label_saya:: +``` + + + +```yue +::mulai:: +::selesai:: +::label_saya:: +``` + + + +Pernyataan goto melompat ke label yang ditentukan: + +```yuescript +a = 0 +::mulai:: +a += 1 +goto selesai if a == 5 +goto mulai +::selesai:: +print "a sekarang 5" +``` + + + +```yue +a = 0 +::mulai:: +a += 1 +goto selesai if a == 5 +goto mulai +::selesai:: +print "a sekarang 5" +``` + + + +Pernyataan goto berguna untuk keluar dari loop yang bersarang dalam: + +```yuescript +for z = 1, 10 + for y = 1, 10 do for x = 1, 10 + if x^2 + y^2 == z^2 + print 'tripel Pythagorean ditemukan:', 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 'tripel Pythagorean ditemukan:', x, y, z + goto ok +::ok:: +``` + + + +Anda juga dapat menggunakan label untuk melompat ke tingkat loop tertentu: + +```yuescript +for z = 1, 10 + for y = 1, 10 + for x = 1, 10 + if x^2 + y^2 == z^2 + print 'tripel Pythagorean ditemukan:', x, y, z + print 'mencoba z berikutnya...' + goto zcontinue + ::zcontinue:: +``` + + + +```yue +for z = 1, 10 + for y = 1, 10 + for x = 1, 10 + if x^2 + y^2 == z^2 + print 'tripel Pythagorean ditemukan:', x, y, z + print 'mencoba z berikutnya...' + goto zcontinue + ::zcontinue:: +``` + + + +## Catatan + +- Label harus unik dalam cakupannya +- goto dapat melompat ke label pada tingkat cakupan yang sama atau luar +- goto tidak dapat melompat ke cakupan dalam (seperti di dalam blok atau loop) +- Gunakan goto dengan hemat, karena dapat membuat kode lebih sulit dibaca dan dipelihara -- cgit v1.2.3-55-g6feb