|
1 |
| -The task demonstrates how postfix/prefix forms can lead to different results when used in comparisons. |
| 1 | +Tugas mendemonstrasikan bagaimana bentuk postfix/prefix dapat menyebabkan hasil yang berbeda ketika digunakan dalam perbandingan |
2 | 2 |
|
3 |
| -1. **From 1 to 4** |
| 3 | +1. **Dari 1 ke 4** |
4 | 4 |
|
5 | 5 | ```js run
|
6 | 6 | let i = 0;
|
7 | 7 | while (++i < 5) alert( i );
|
8 | 8 | ```
|
9 | 9 |
|
10 |
| - The first value is `i = 1`, because `++i` first increments `i` and then returns the new value. So the first comparison is `1 < 5` and the `alert` shows `1`. |
| 10 | + nilai pertama adalah `i = 1`, karena `++i` pertama menaikan `i` dan mengembalikan nilai baru. Jadi perbandingan pertama adalah `1 < 5` dan `alert` menampilkan `1`. |
11 | 11 |
|
12 |
| - Then follow `2, 3, 4…` -- the values show up one after another. The comparison always uses the incremented value, because `++` is before the variable. |
| 12 | + lalu diikuti `2, 3, 4…` -- nilainya muncul satu per satu. Perbandingan selalu menggunakan nilai yang ditambah, karna `++` sebelum variabel. |
13 | 13 |
|
14 |
| - Finally, `i = 4` is incremented to `5`, the comparison `while(5 < 5)` fails, and the loop stops. So `5` is not shown. |
15 |
| -2. **From 1 to 5** |
| 14 | + Akhirnya, `i = 4` naik menjadi `5`, perbandingan `while(5 < 5)` gagal, dan pengulangan berhenti. Jadi `5` tidak ditampilkan. |
| 15 | +2. **Dari 1 ke 5** |
16 | 16 |
|
17 | 17 | ```js run
|
18 | 18 | let i = 0;
|
19 | 19 | while (i++ < 5) alert( i );
|
20 | 20 | ```
|
21 | 21 |
|
22 |
| - The first value is again `i = 1`. The postfix form of `i++` increments `i` and then returns the *old* value, so the comparison `i++ < 5` will use `i = 0` (contrary to `++i < 5`). |
| 22 | + Lagi, nilai pertama adalah `i = 1`. bentuk postfix dari `i++` menaikan `i` lalu mengembalikan nilai yang *lama*, jadi perbandinganya `i++ < 5` akan menggunakan `i = 0` (berbeda dengan `++i < 5`). |
23 | 23 |
|
24 |
| - But the `alert` call is separate. It's another statement which executes after the increment and the comparison. So it gets the current `i = 1`. |
| 24 | + Namun panggilan `alert` terpisah. ini adalah pernyataan lain yang berjalan setelah kenaikan dan perbandingan. Jadi ini mendapatkan yang sekarang `i = 1`. |
25 | 25 |
|
26 |
| - Then follow `2, 3, 4…` |
| 26 | + Lalu diikuti `2, 3, 4…` |
27 | 27 |
|
28 |
| - Let's stop on `i = 4`. The prefix form `++i` would increment it and use `5` in the comparison. But here we have the postfix form `i++`. So it increments `i` to `5`, but returns the old value. Hence the comparison is actually `while(4 < 5)` -- true, and the control goes on to `alert`. |
| 28 | + Mari berhenti di `i = 4`. bentuk prefix `++i` akan menaikannya dan menggunakan `5` di perbandingan. Tapi disini kita mempunyai bentuk postfix `i++`. jadi ini menaikan `i` ke `5`, namun mengembalikan nilai yang lama. Karna perbandingan yang sebenarnya adalah `while(4 < 5)` -- benar, dan kontrol berlanjut ke `alert`. |
29 | 29 |
|
30 |
| - The value `i = 5` is the last one, because on the next step `while(5 < 5)` is false. |
| 30 | + Nilai `i = 5` adalah yang terkahir, karena pada langkah berikutnya `while(5 < 5)` adalah salah. |
0 commit comments