Skip to content

Commit 483a052

Browse files
authored
Update article.md
1 parent a4518ed commit 483a052

File tree

1 file changed

+53
-53
lines changed

1 file changed

+53
-53
lines changed

1-js/02-first-steps/12-while-for/article.md

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
1-
# Loops: while and for
1+
# Ciklai: while ir for
22

3-
We often need to repeat actions.
3+
Mes dažnai turime pakartoti veiksmus.
44

5-
For example, outputting goods from a list one after another or just running the same code for each number from 1 to 10.
5+
Pavyzdžiui, įvairių dalykų išvedimas vienas paskui kitą iš sąrašo, arba paprasčiausiai to paties kodo paliedimas kiekvienam numeriui nuo 1 iki 10.
66

7-
*Loops* are a way to repeat the same code multiple times.
7+
*Cilkai* (ang. *Loops*) yra būdas pakartoti daug kartų tą patį kodą.
88

9-
## The "while" loop
9+
## Ciklas "while"
1010

11-
The `while` loop has the following syntax:
11+
Ciklas `while` turi sekančią sintaksę:
1212

1313
```js
1414
while (condition) {
15-
// code
16-
// so-called "loop body"
15+
// kodas
16+
// taip vadinamas "ciklo korpusas" (ang. "loop body")
1717
}
1818
```
1919

20-
While the `condition` is truthy, the `code` from the loop body is executed.
20+
Kol `sąlyga` yra truthy, `kodas` iš ciklo rinkinio yra įvykdomas.
2121

22-
For instance, the loop below outputs `i` while `i < 3`:
22+
Pavyzdžiui, ciklas žemiau atiduoda `i` kol `i < 3`:
2323

2424
```js run
2525
let i = 0;
26-
while (i < 3) { // shows 0, then 1, then 2
26+
while (i < 3) { // parodo 0, tada 1, tada 2
2727
alert( i );
2828
i++;
2929
}
3030
```
3131

32-
A single execution of the loop body is called *an iteration*. The loop in the example above makes three iterations.
32+
Vienas ciklo rinkinio įvykdymas vadinamas *iteracija* (ang. *an iteration*). Ciklas pavyzdyje aukščiau padaro tris iteracijas.
3333

34-
If `i++` was missing from the example above, the loop would repeat (in theory) forever. In practice, the browser provides ways to stop such loops, and in server-side JavaScript, we can kill the process.
34+
Jeigu kodo pavyzdyje viršuje nebūtų `i++`, ciklas (teoriškai) kartotųsi amžinai. Praktiškai, naršyklė suteikia būdų sustabdyti tokį ciklą ir procesas gali būti užbaigtas serverio pusės JavaScript.
3535

36-
Any expression or variable can be a loop condition, not just comparisons: the condition is evaluated and converted to a boolean by `while`.
36+
Bet kokia išraiška arba kintamasis gali būti ciklo sąlyga, ne tik palyginimas: sąlyga yra įvertinama ir `while` paverčiama į loginį sprendimą.
3737

38-
For instance, a shorter way to write `while (i != 0)` is `while (i)`:
38+
Pavyzdžiui, trumpesnis būdas parašyti `while (i != 0)` yra `while (i)`:
3939

4040
```js run
4141
let i = 3;
4242
*!*
43-
while (i) { // when i becomes 0, the condition becomes falsy, and the loop stops
43+
while (i) { // kai i pavirsta 0, sąlyga tampa falsy ir ciklas sustoja
4444
*/!*
4545
alert( i );
4646
i--;
4747
}
4848
```
4949

50-
````smart header="Curly braces are not required for a single-line body"
51-
If the loop body has a single statement, we can omit the curly braces `{…}`:
50+
````smart header="Riestiniai skliaustai nėra reikalingi vienos eilės korpusui"
51+
Jeigu ciklo kopusas turi tik vieną teiginį, galime nenaudoti riestinių skliaustų `{…}`:
5252
5353
```js run
5454
let i = 3;
@@ -58,19 +58,19 @@ while (i) alert(i--);
5858
```
5959
````
6060

61-
## The "do..while" loop
61+
## Ciklas "do..while"
6262

63-
The condition check can be moved *below* the loop body using the `do..while` syntax:
63+
Sąlygos patikrinimas gali būtų perkeltas *žemiau* ciklo korpuso naudojant sintaksę `do..while`:
6464

6565
```js
6666
do {
67-
// loop body
68-
} while (condition);
67+
// ciklo korpusas
68+
} while (sąlyga);
6969
```
7070

71-
The loop will first execute the body, then check the condition, and, while it's truthy, execute it again and again.
71+
Ciklas visų pirma įvykdys korpusą, tada patikrins sąlygą ir kol ji yra truthy, įvykdys vėl ir vėl.
7272

73-
For example:
73+
Pavyzdžiui:
7474

7575
```js run
7676
let i = 0;
@@ -80,69 +80,69 @@ do {
8080
} while (i < 3);
8181
```
8282

83-
This form of syntax should only be used when you want the body of the loop to execute **at least once** regardless of the condition being truthy. Usually, the other form is preferred: `while(…) {…}`.
83+
Tokia sintaksė turėtų būti naudojama kai norite, kad ciklo korpusas būtų įvykdytas **bent vieną kartą** nepaisant to ar jo sąlyga yra truthy. Dažniausiai vis dėlto naudojama kita forma: `while(…) {…}`.
8484

85-
## The "for" loop
85+
## Ciklas "for"
8686

87-
The `for` loop is more complex, but it's also the most commonly used loop.
87+
Ciklas `for` yra kiek sudėtingesnis, bet jis taip pat yra dažniausiai naudojamas ciklas.
8888

89-
It looks like this:
89+
Jis atrodo taip:
9090

9191
```js
92-
for (begin; condition; step) {
93-
// ... loop body ...
92+
for (begin; condition; step) { // pradžia; sąlyga; žingsnis
93+
// ... ciklo korpusas ...
9494
}
9595
```
9696

97-
Let's learn the meaning of these parts by example. The loop below runs `alert(i)` for `i` from `0` up to (but not including) `3`:
97+
Išmokime šių dalių reikšmę su pavyzdžiais. Ciklas žemiau paleidžia `alert(i)` dėl `i` nuo `0` iki (bet neįskaitant) `3`:
9898

9999
```js run
100-
for (let i = 0; i < 3; i++) { // shows 0, then 1, then 2
100+
for (let i = 0; i < 3; i++) { // parodo 0, tada 1, tada 2
101101
alert(i);
102102
}
103103
```
104104

105-
Let's examine the `for` statement part-by-part:
105+
Ištikrime teiginį `for` dalis po dalies:
106106

107-
| part | | |
107+
| dalis | | |
108108
|-------|----------|----------------------------------------------------------------------------|
109-
| begin | `i = 0` | Executes once upon entering the loop. |
110-
| condition | `i < 3`| Checked before every loop iteration. If false, the loop stops. |
111-
| body | `alert(i)`| Runs again and again while the condition is truthy. |
112-
| step| `i++` | Executes after the body on each iteration. |
109+
| pradžia | `i = 0` | Įvykdomas vieną kartą pradedant ciklą |
110+
| salyga | `i < 3`| Patikrinama prieš kiekvieną ciklo iteraciją. Jeigu netiesa, ciklas sustoja |
111+
| korpusas | `alert(i)`| Įvykdomas vėl ir vėl kol sąlyga yra truthy. |
112+
| žingsnis | `i++` | Įvykdomas po korpuso per kiekvieną iteraciją. |
113113

114-
The general loop algorithm works like this:
114+
Įprastinio ciklo algoritmasveikia taip:
115115

116116
```
117-
Run begin
118-
→ (if conditionrun body and run step)
119-
→ (if conditionrun body and run step)
120-
→ (if conditionrun body and run step)
117+
Pradedamas vykdymas
118+
→ (jeigu sąlygapaleisti korpusą ir paleisti žingsnį)
119+
→ (jeigu sąlygapaleisti korpusą ir paleisti žingsnį)
120+
→ (jeigu sąlygapaleisti korpusą ir paleisti žingsnį)
121121
→ ...
122122
```
123123

124-
That is, `begin` executes once, and then it iterates: after each `condition` test, `body` and `step` are executed.
124+
Tai yra, `begin` įvykdomas vieną kartą ir tada jis kartojasi (ang. iterates): po kiekvieno `sąlygos` testo, įvykdomi `korpusas` ir `žingsnis`.
125125

126-
If you are new to loops, it could help to go back to the example and reproduce how it runs step-by-step on a piece of paper.
126+
Jeigu ciklai jums naujiena, padėtų juos geriau suprasti, jeigu sugrįžtumėte prie pavyzdžio ir atkurtumėte kaip jis veikia žingsnis po žingsnio ant popieriaus lapo.
127127

128-
Here's exactly what happens in our case:
128+
Štai kas konkrečiai vyksta mūsų atveju:
129129

130130
```js
131131
// for (let i = 0; i < 3; i++) alert(i)
132132

133-
// run begin
133+
// pradedamas vykdymas
134134
let i = 0
135-
// if conditionrun body and run step
135+
// jeigu sąlygapaleisti korpusą ir paleisti žingsnį
136136
if (i < 3) { alert(i); i++ }
137-
// if conditionrun body and run step
137+
// jeigu sąlygapaleisti korpusą ir paleisti žingsnį
138138
if (i < 3) { alert(i); i++ }
139-
// if conditionrun body and run step
139+
// jeigu sąlygapaleisti korpusą ir paleisti žingsnį
140140
if (i < 3) { alert(i); i++ }
141-
// ...finish, because now i == 3
141+
// ...pabaiga, nes dabar i == 3
142142
```
143143

144-
````smart header="Inline variable declaration"
145-
Here, the "counter" variable `i` is declared right in the loop. This is called an "inline" variable declaration. Such variables are visible only inside the loop.
144+
````smart header="Įterptojo kintamojo deklaracija"
145+
Čia "skaičiuojantis" (ang. "counter") kintamasis `i` yra deklaruotas tiesis cikle. is declared right in the loop. This is called an "inline" variable declaration. Such variables are visible only inside the loop.
146146
147147
```js run
148148
for (*!*let*/!* i = 0; i < 3; i++) {

0 commit comments

Comments
 (0)