Skip to content

Commit 6327f3c

Browse files
authored
Translated solution.md
1 parent 959f215 commit 6327f3c

File tree

1 file changed

+11
-11
lines changed
  • 1-js/02-first-steps/12-while-for/2-which-value-while

1 file changed

+11
-11
lines changed
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
The task demonstrates how postfix/prefix forms can lead to different results when used in comparisons.
1+
Užduotis parodo kaip priešdėlinė/podėlinė formos gali atvesti prie skirtingų rezultatų kai naudojamos palyginimui.
22

3-
1. **From 1 to 4**
3+
1. **Nuo 1 iki 4**
44

55
```js run
66
let i = 0;
77
while (++i < 5) alert( i );
88
```
99

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+
Pirmoji vertė yra `i = 1`, nes `++i` pirma padidina `i` ir tada sugrąžina naują vertę. Tad pirmasis palyginimas yra `1 < 5` ir `alert` parodo `1`.
1111

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+
Tada seka `2, 3, 4…` -- vertės pasirodo viena po kitos. Palyginimui visada naudojama jau padidinta vertė, nes `++` yra prieš kintamąjį.
1313

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+
Galų gale, `i = 4` yra padidinamas iki `5`, tad palyginimas `while(5 < 5)` yra netiesa ir ciklas sustoja. Tad `5` nėra parodomas.
15+
2. **Nuo 1 iki 5**
1616

1717
```js run
1818
let i = 0;
1919
while (i++ < 5) alert( i );
2020
```
2121

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+
Pirmoji vertė vėlgi yra `i = 1`. Podėlinė `i++` forma padidina `i` ir tada sugrąžina *senąją* vertę, tad palyginimas `i++ < 5` naudos `i = 0` (priešingai nei `++i < 5`).
2323

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+
Bet šaukimas `alert` yra atskiras, Tai yra kitas teiginys, kuris yra įvykdomas po padidinimo ir palyginimo. Tad jis gauna esamą `i = 1`.
2525

26-
Then follow `2, 3, 4…`
26+
Toliau seka `2, 3, 4…`
2727

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+
Sustokime prie `i = 4`. Priešdėlinė forma `++i` padidintų jį ir naudotų `5` palyginime. Bet čia mes turime podėlinę formą `i++`. Tad ji padidina `i` iki `5`, bet grąžina senąją vertę. Dėl to palyginimas yra iš tikrųjų `while(4 < 5)` -- tiesa, ir controlė pereina prie `alert`.
2929

30-
The value `i = 5` is the last one, because on the next step `while(5 < 5)` is false.
30+
Vertė `i = 5` yra paskutinė, nes sekančiame žingsnyje `while(5 < 5)` būtų netiesa.

0 commit comments

Comments
 (0)