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/docs/id-id | |
| parent | ecd8f3bfd07e91d04e0a2d72f4a50f9cc6c75433 (diff) | |
| download | yuescript-cf5b1b4a68d762e6e33cac8367611ecea15fa942.tar.gz yuescript-cf5b1b4a68d762e6e33cac8367611ecea15fa942.tar.bz2 yuescript-cf5b1b4a68d762e6e33cac8367611ecea15fa942.zip | |
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 <noreply@anthropic.com>
Diffstat (limited to 'doc/docs/id-id')
| -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 |
2 files changed, 164 insertions, 0 deletions
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 | ||
