From 483a052a7c04f9ec9d7b37d3f7d3d37de9690de0 Mon Sep 17 00:00:00 2001 From: Ginja <30539630+meilune@users.noreply.github.com> Date: Mon, 9 Aug 2021 17:14:08 +1000 Subject: [PATCH 01/19] Update article.md --- 1-js/02-first-steps/12-while-for/article.md | 106 ++++++++++---------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/1-js/02-first-steps/12-while-for/article.md b/1-js/02-first-steps/12-while-for/article.md index 382adadac..730d0ceb8 100644 --- a/1-js/02-first-steps/12-while-for/article.md +++ b/1-js/02-first-steps/12-while-for/article.md @@ -1,54 +1,54 @@ -# Loops: while and for +# Ciklai: while ir for -We often need to repeat actions. +Mes dažnai turime pakartoti veiksmus. -For example, outputting goods from a list one after another or just running the same code for each number from 1 to 10. +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. -*Loops* are a way to repeat the same code multiple times. +*Cilkai* (ang. *Loops*) yra būdas pakartoti daug kartų tą patį kodą. -## The "while" loop +## Ciklas "while" -The `while` loop has the following syntax: +Ciklas `while` turi sekančią sintaksę: ```js while (condition) { - // code - // so-called "loop body" + // kodas + // taip vadinamas "ciklo korpusas" (ang. "loop body") } ``` -While the `condition` is truthy, the `code` from the loop body is executed. +Kol `sąlyga` yra truthy, `kodas` iš ciklo rinkinio yra įvykdomas. -For instance, the loop below outputs `i` while `i < 3`: +Pavyzdžiui, ciklas žemiau atiduoda `i` kol `i < 3`: ```js run let i = 0; -while (i < 3) { // shows 0, then 1, then 2 +while (i < 3) { // parodo 0, tada 1, tada 2 alert( i ); i++; } ``` -A single execution of the loop body is called *an iteration*. The loop in the example above makes three iterations. +Vienas ciklo rinkinio įvykdymas vadinamas *iteracija* (ang. *an iteration*). Ciklas pavyzdyje aukščiau padaro tris iteracijas. -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. +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. -Any expression or variable can be a loop condition, not just comparisons: the condition is evaluated and converted to a boolean by `while`. +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ą. -For instance, a shorter way to write `while (i != 0)` is `while (i)`: +Pavyzdžiui, trumpesnis būdas parašyti `while (i != 0)` yra `while (i)`: ```js run let i = 3; *!* -while (i) { // when i becomes 0, the condition becomes falsy, and the loop stops +while (i) { // kai i pavirsta 0, sąlyga tampa falsy ir ciklas sustoja */!* alert( i ); i--; } ``` -````smart header="Curly braces are not required for a single-line body" -If the loop body has a single statement, we can omit the curly braces `{…}`: +````smart header="Riestiniai skliaustai nėra reikalingi vienos eilės korpusui" +Jeigu ciklo kopusas turi tik vieną teiginį, galime nenaudoti riestinių skliaustų `{…}`: ```js run let i = 3; @@ -58,19 +58,19 @@ while (i) alert(i--); ``` ```` -## The "do..while" loop +## Ciklas "do..while" -The condition check can be moved *below* the loop body using the `do..while` syntax: +Sąlygos patikrinimas gali būtų perkeltas *žemiau* ciklo korpuso naudojant sintaksę `do..while`: ```js do { - // loop body -} while (condition); + // ciklo korpusas +} while (sąlyga); ``` -The loop will first execute the body, then check the condition, and, while it's truthy, execute it again and again. +Ciklas visų pirma įvykdys korpusą, tada patikrins sąlygą ir kol ji yra truthy, įvykdys vėl ir vėl. -For example: +Pavyzdžiui: ```js run let i = 0; @@ -80,69 +80,69 @@ do { } while (i < 3); ``` -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(…) {…}`. +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(…) {…}`. -## The "for" loop +## Ciklas "for" -The `for` loop is more complex, but it's also the most commonly used loop. +Ciklas `for` yra kiek sudėtingesnis, bet jis taip pat yra dažniausiai naudojamas ciklas. -It looks like this: +Jis atrodo taip: ```js -for (begin; condition; step) { - // ... loop body ... +for (begin; condition; step) { // pradžia; sąlyga; žingsnis + // ... ciklo korpusas ... } ``` -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`: +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`: ```js run -for (let i = 0; i < 3; i++) { // shows 0, then 1, then 2 +for (let i = 0; i < 3; i++) { // parodo 0, tada 1, tada 2 alert(i); } ``` -Let's examine the `for` statement part-by-part: +Ištikrime teiginį `for` dalis po dalies: -| part | | | +| dalis | | | |-------|----------|----------------------------------------------------------------------------| -| begin | `i = 0` | Executes once upon entering the loop. | -| condition | `i < 3`| Checked before every loop iteration. If false, the loop stops. | -| body | `alert(i)`| Runs again and again while the condition is truthy. | -| step| `i++` | Executes after the body on each iteration. | +| pradžia | `i = 0` | Įvykdomas vieną kartą pradedant ciklą | +| salyga | `i < 3`| Patikrinama prieš kiekvieną ciklo iteraciją. Jeigu netiesa, ciklas sustoja | +| korpusas | `alert(i)`| Įvykdomas vėl ir vėl kol sąlyga yra truthy. | +| žingsnis | `i++` | Įvykdomas po korpuso per kiekvieną iteraciją. | -The general loop algorithm works like this: +Įprastinio ciklo algoritmasveikia taip: ``` -Run begin -→ (if condition → run body and run step) -→ (if condition → run body and run step) -→ (if condition → run body and run step) +Pradedamas vykdymas +→ (jeigu sąlyga → paleisti korpusą ir paleisti žingsnį) +→ (jeigu sąlyga → paleisti korpusą ir paleisti žingsnį) +→ (jeigu sąlyga → paleisti korpusą ir paleisti žingsnį) → ... ``` -That is, `begin` executes once, and then it iterates: after each `condition` test, `body` and `step` are executed. +Tai yra, `begin` įvykdomas vieną kartą ir tada jis kartojasi (ang. iterates): po kiekvieno `sąlygos` testo, įvykdomi `korpusas` ir `žingsnis`. -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. +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. -Here's exactly what happens in our case: +Štai kas konkrečiai vyksta mūsų atveju: ```js // for (let i = 0; i < 3; i++) alert(i) -// run begin +// pradedamas vykdymas let i = 0 -// if condition → run body and run step +// jeigu sąlyga → paleisti korpusą ir paleisti žingsnį if (i < 3) { alert(i); i++ } -// if condition → run body and run step +// jeigu sąlyga → paleisti korpusą ir paleisti žingsnį if (i < 3) { alert(i); i++ } -// if condition → run body and run step +// jeigu sąlyga → paleisti korpusą ir paleisti žingsnį if (i < 3) { alert(i); i++ } -// ...finish, because now i == 3 +// ...pabaiga, nes dabar i == 3 ``` -````smart header="Inline variable declaration" -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. +````smart header="Įterptojo kintamojo deklaracija" +Č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. ```js run for (*!*let*/!* i = 0; i < 3; i++) { From 48af2f3ecf4bb5ce20de305c27aa31b35293917a Mon Sep 17 00:00:00 2001 From: Ginja <30539630+meilune@users.noreply.github.com> Date: Mon, 9 Aug 2021 21:22:56 +1000 Subject: [PATCH 02/19] Update article.md --- 1-js/02-first-steps/12-while-for/article.md | 70 ++++++++++----------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/1-js/02-first-steps/12-while-for/article.md b/1-js/02-first-steps/12-while-for/article.md index 730d0ceb8..311b58ec0 100644 --- a/1-js/02-first-steps/12-while-for/article.md +++ b/1-js/02-first-steps/12-while-for/article.md @@ -102,16 +102,16 @@ for (let i = 0; i < 3; i++) { // parodo 0, tada 1, tada 2 } ``` -Ištikrime teiginį `for` dalis po dalies: +Ištirkime teiginį `for` dalis po dalies: | dalis | | | |-------|----------|----------------------------------------------------------------------------| -| pradžia | `i = 0` | Įvykdomas vieną kartą pradedant ciklą | -| salyga | `i < 3`| Patikrinama prieš kiekvieną ciklo iteraciją. Jeigu netiesa, ciklas sustoja | +| pradžia | `i = 0` | Įvykdomas vieną kartą pradedant ciklą. | +| salyga | `i < 3`| Patikrinama prieš kiekvieną ciklo iteraciją. Jeigu netiesa, ciklas sustoja. | | korpusas | `alert(i)`| Įvykdomas vėl ir vėl kol sąlyga yra truthy. | | žingsnis | `i++` | Įvykdomas po korpuso per kiekvieną iteraciją. | -Įprastinio ciklo algoritmasveikia taip: +Įprastinio ciklo algoritmas veikia taip: ``` Pradedamas vykdymas @@ -123,7 +123,7 @@ Pradedamas vykdymas Tai yra, `begin` įvykdomas vieną kartą ir tada jis kartojasi (ang. iterates): po kiekvieno `sąlygos` testo, įvykdomi `korpusas` ir `žingsnis`. -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. +Jeigu ciklai jums naujiena, juos geriau suprasti padėtų , jeigu sugrįžtumėte prie pavyzdžio ir žingsnis po žingsnio atkurtumėte kaip jis veikia ant popieriaus lapo. Štai kas konkrečiai vyksta mūsų atveju: @@ -142,47 +142,47 @@ if (i < 3) { alert(i); i++ } ``` ````smart header="Įterptojo kintamojo deklaracija" -Č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. +Čia "skaičiuojantis" (ang. "counter") kintamasis `i` yra deklaruotas tiesiai cikle. Tai vadinama "įterptojo" (ang. "inline") kintamojo deklaracija. Toks kintamasis yra matomas tik ciklo viduje. ```js run for (*!*let*/!* i = 0; i < 3; i++) { alert(i); // 0, 1, 2 } -alert(i); // error, no such variable +alert(i); // klaida, tokio kintamojo nėra ``` -Instead of defining a variable, we could use an existing one: +Vietoje to, kad apibrėžtume kintamąjį, galime naudoti jau egzituojantį: ```js run let i = 0; -for (i = 0; i < 3; i++) { // use an existing variable +for (i = 0; i < 3; i++) { // naudojamas jau egzituojantis kintamasis alert(i); // 0, 1, 2 } -alert(i); // 3, visible, because declared outside of the loop +alert(i); // 3, matomas, nes deklaruotas už ciklo ribų ``` ```` -### Skipping parts +### Dalių praleidimas -Any part of `for` can be skipped. +Bet kuri `for` dalis gali būti praleista. -For example, we can omit `begin` if we don't need to do anything at the loop start. +Pavyzdžiui, mes galime neįtraukti `begin`, jeigu mums nieko nereikia daryti ciklo pradžioje. -Like here: +Kaip šiame pavyzdyje: ```js run -let i = 0; // we have i already declared and assigned +let i = 0; // jau turime deklaravę ir priskyrę i -for (; i < 3; i++) { // no need for "begin" +for (; i < 3; i++) { // nereikia "pradžios" alert( i ); // 0, 1, 2 } ``` -We can also remove the `step` part: +Taip pat galime nenaudoti `žingsnio` dalies: ```js run let i = 0; @@ -192,32 +192,32 @@ for (; i < 3;) { } ``` -This makes the loop identical to `while (i < 3)`. +Tai padaro ciklą identišku `while (i < 3)`. -We can actually remove everything, creating an infinite loop: +Mes netgi galime viską panaikinti, sukurdami begalinį ciklą: ```js for (;;) { - // repeats without limits + // kartojasi be ribų } ``` -Please note that the two `for` semicolons `;` must be present. Otherwise, there would be a syntax error. +Atkreipkite dėmesį, kad du `for` kabliataškiai `;` myra privalomi. Kitu atveju bus sintaksės klaida. -## Breaking the loop +## Ciklo nutraukimas -Normally, a loop exits when its condition becomes falsy. +Dažniausiai, ciklas egzituoja kol jo sąlyga tampa falsy. -But we can force the exit at any time using the special `break` directive. +Bet mes galime priverstinai išeiti naudodami ypatingają `break` direktyvą. -For example, the loop below asks the user for a series of numbers, "breaking" when no number is entered: +Pavyzdžiui, ciklas žemiau klausia naudotojo numerių serijos, "nutraukdamas" kai nėra įvedamas skaičius: ```js run let sum = 0; while (true) { - let value = +prompt("Enter a number", ''); + let value = +prompt("Įveskite skaičių", ''); *!* if (!value) break; // (*) @@ -226,32 +226,32 @@ while (true) { sum += value; } -alert( 'Sum: ' + sum ); +alert( 'Suma: ' + sum ); ``` -The `break` directive is activated at the line `(*)` if the user enters an empty line or cancels the input. It stops the loop immediately, passing control to the first line after the loop. Namely, `alert`. +Direktyva `break` yra aktyvuojama eilutėje `(*)`, jeigu lankytojas pateikia tuščią rezultatą arba atšaukia įvedimą. Tai iš karto sustabdo ciklą, perduodant kontrolę pirmai eilei po ciklo. Šiuo atveju `alert`. -The combination "infinite loop + `break` as needed" is great for situations when a loop's condition must be checked not in the beginning or end of the loop, but in the middle or even in several places of its body. +Kombinacija "bagalinis ciklas + `break` kai reikia" yra gerai tokiose situacijose kai ciklo sąlyga turi būti patikrinama ne pačioje pradžio ar pabaigoje ciklo, bet viduryje arba netgi keliose jo korpuso vietose. -## Continue to the next iteration [#continue] +## Tęsinys kitoje iteracijoje [#continue] -The `continue` directive is a "lighter version" of `break`. It doesn't stop the whole loop. Instead, it stops the current iteration and forces the loop to start a new one (if the condition allows). +Direktyva `continue` (tęsti) yra "lengvesnė versija" direktyvos `break`. Ji nesustobado viso ciklo. Vietoje to, ji sustabdo esamą iteraciją ir priverčią ciklą pradėti naują iteraciją (jeigu sąlyga tai leidžia). -We can use it if we're done with the current iteration and would like to move on to the next one. +Galime tai naudoti kai baihiame su esama iteracija ir esame pasiruošę pereiti prie sekančios. -The loop below uses `continue` to output only odd values: +Ciklas žemiau naudoja `continue`, kad atiduotų tik nelygines vertes: ```js run no-beautify for (let i = 0; i < 10; i++) { - // if true, skip the remaining part of the body + // jeigu tiesa, praleisti likusią korpuso dalį *!*if (i % 2 == 0) continue;*/!* alert(i); // 1, then 3, 5, 7, 9 } ``` -For even values of `i`, the `continue` directive stops executing the body and passes control to the next iteration of `for` (with the next number). So the `alert` is only called for odd values. +Lyginėms `i` vertėms, direktyva `continue` nustoja vykdyti korpusą ir perleidžia kontrolę sekančiai `for` iteracijai (su sekančiu skaičiumi). Tad `alert` yra iškviečiamas tik nelyginėms vertėms. ````smart header="The `continue` directive helps decrease nesting" A loop that shows odd values could look like this: From 7c973dad223fdcf2dc4f4e38bd2b24865ee6747e Mon Sep 17 00:00:00 2001 From: Ginja <30539630+meilune@users.noreply.github.com> Date: Tue, 10 Aug 2021 18:08:52 +1000 Subject: [PATCH 03/19] Update article.md --- 1-js/02-first-steps/12-while-for/article.md | 30 ++++++++++----------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/1-js/02-first-steps/12-while-for/article.md b/1-js/02-first-steps/12-while-for/article.md index 311b58ec0..a6dc59ba0 100644 --- a/1-js/02-first-steps/12-while-for/article.md +++ b/1-js/02-first-steps/12-while-for/article.md @@ -2,7 +2,7 @@ Mes dažnai turime pakartoti veiksmus. -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. +Pavyzdžiui, įvairių prekių išbraukimas viena paskui kitą iš sąrašo, arba paprasčiausiai to paties kodo paleidimas kiekvienam numeriui nuo 1 iki 10. *Cilkai* (ang. *Loops*) yra būdas pakartoti daug kartų tą patį kodą. @@ -237,7 +237,7 @@ Kombinacija "bagalinis ciklas + `break` kai reikia" yra gerai tokiose situacijos Direktyva `continue` (tęsti) yra "lengvesnė versija" direktyvos `break`. Ji nesustobado viso ciklo. Vietoje to, ji sustabdo esamą iteraciją ir priverčią ciklą pradėti naują iteraciją (jeigu sąlyga tai leidžia). -Galime tai naudoti kai baihiame su esama iteracija ir esame pasiruošę pereiti prie sekančios. +Galime tai naudoti kai baigiame su esama iteracija ir esame pasiruošę pereiti prie sekančios. Ciklas žemiau naudoja `continue`, kad atiduotų tik nelygines vertes: @@ -247,14 +247,14 @@ for (let i = 0; i < 10; i++) { // jeigu tiesa, praleisti likusią korpuso dalį *!*if (i % 2 == 0) continue;*/!* - alert(i); // 1, then 3, 5, 7, 9 + alert(i); // 1, tada 3, 5, 7, 9 } ``` Lyginėms `i` vertėms, direktyva `continue` nustoja vykdyti korpusą ir perleidžia kontrolę sekančiai `for` iteracijai (su sekančiu skaičiumi). Tad `alert` yra iškviečiamas tik nelyginėms vertėms. -````smart header="The `continue` directive helps decrease nesting" -A loop that shows odd values could look like this: +````smart header="Direktyva `continue` sumažina matrioškinį kodą (ang. nesting)" +Ciklas, kuris parodo nelygines vertes gali atrodyti taip: ```js for (let i = 0; i < 10; i++) { @@ -266,15 +266,15 @@ for (let i = 0; i < 10; i++) { } ``` -From a technical point of view, this is identical to the example above. Surely, we can just wrap the code in an `if` block instead of using `continue`. +Iš techninės perspektyvos tai yra visiškai identiškas kodas pavyzdžiui aukšąiau. Žinoma, mes galime tiesiog apgobti `if` rinkinį vietoje to, kad naudotume `continue`. -But as a side-effect, this created one more level of nesting (the `alert` call inside the curly braces). If the code inside of`if` is longer than a few lines, that may decrease the overall readability. +Bet to pašalinis efektas yra papildomas matrioškinis lygis (šaukimas `alert` viduje riestinių skliaustų). O jeigu kodas `if` viduje yra ilgesnis nei kelios eilės, tai apsunkina skaitomumą. ```` -````warn header="No `break/continue` to the right side of '?'" -Please note that syntax constructs that are not expressions cannot be used with the ternary operator `?`. In particular, directives such as `break/continue` aren't allowed there. +````warn header="Jokių `break/continue` dešinėje '?' pusėje" +Atkreipkite dėmesį, kad sintaksiniai konstruktai, kurie nėra išraiškos, negalimi su ternariniu operatoriumi `?`. Ypatingai tokios direktyvos kaip `break/continue` yra neleidžiamos. -For example, if we take this code: +Pavyzdžiui, jeigu paimtume tokį kodą: ```js if (i > 5) { @@ -284,19 +284,19 @@ if (i > 5) { } ``` -...and rewrite it using a question mark: +...ir perrašytume jį naudodami klaustuką: ```js no-beautify -(i > 5) ? alert(i) : *!*continue*/!*; // continue isn't allowed here +(i > 5) ? alert(i) : *!*continue*/!*; // continue nėra čią leidžiamas ``` -...it stops working: there's a syntax error. +...jis nustoja veikti: tai yra sintaksinė klaida. -This is just another reason not to use the question mark operator `?` instead of `if`. +Tai tik dar viena priežastis nenaudoti klaustuko operatoriaus `?` vietoje`if`. ```` -## Labels for break/continue +## Etiketės break/continue Sometimes we need to break out from multiple nested loops at once. From 462d9e3fbbd47b35418ae10a058bcfa46429fcbc Mon Sep 17 00:00:00 2001 From: Ginja <30539630+meilune@users.noreply.github.com> Date: Wed, 11 Aug 2021 06:32:39 +1000 Subject: [PATCH 04/19] Translated article.md --- 1-js/02-first-steps/12-while-for/article.md | 100 ++++++++++---------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/1-js/02-first-steps/12-while-for/article.md b/1-js/02-first-steps/12-while-for/article.md index a6dc59ba0..894181366 100644 --- a/1-js/02-first-steps/12-while-for/article.md +++ b/1-js/02-first-steps/12-while-for/article.md @@ -4,14 +4,14 @@ Mes dažnai turime pakartoti veiksmus. Pavyzdžiui, įvairių prekių išbraukimas viena paskui kitą iš sąrašo, arba paprasčiausiai to paties kodo paleidimas kiekvienam numeriui nuo 1 iki 10. -*Cilkai* (ang. *Loops*) yra būdas pakartoti daug kartų tą patį kodą. +*Ciklai* (ang. *Loops*) yra būdas pakartoti daug kartų tą patį kodą. ## Ciklas "while" Ciklas `while` turi sekančią sintaksę: ```js -while (condition) { +while (sąlyga) { // kodas // taip vadinamas "ciklo korpusas" (ang. "loop body") } @@ -31,9 +31,9 @@ while (i < 3) { // parodo 0, tada 1, tada 2 Vienas ciklo rinkinio įvykdymas vadinamas *iteracija* (ang. *an iteration*). Ciklas pavyzdyje aukščiau padaro tris iteracijas. -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. +Jeigu kodo pavyzdyje viršuje nebūtų `i++`, ciklas (teoriškai) kartotųsi amžinai. Praktikoje naršyklė suteikia būdų sustabdyti tokį ciklą ir procesas gali būti užbaigtas JavaScript serverio pusėje. -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ą. +Bet kokia išraiška arba kintamasis gali būti ciklo sąlyga, ne tik palyginimas: sąlyga yra įvertinama ir `while` ciklo paverčiama į loginį sprendimą. Pavyzdžiui, trumpesnis būdas parašyti `while (i != 0)` yra `while (i)`: @@ -84,7 +84,7 @@ Tokia sintaksė turėtų būti naudojama kai norite, kad ciklo korpusas būtų ## Ciklas "for" -Ciklas `for` yra kiek sudėtingesnis, bet jis taip pat yra dažniausiai naudojamas ciklas. +Ciklas `for` yra kiek sudėtingesnis, bet jis tuo pačiu yra dažniausiai naudojamas ciklas. Jis atrodo taip: @@ -94,7 +94,7 @@ for (begin; condition; step) { // pradžia; sąlyga; žingsnis } ``` -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`: +Išmokime šių dalių reikšmę su pavyzdžiais. Ciklas žemiau paleidžia `alert(i)` kol `i` yra nuo `0` iki (bet neįskaitant) `3`: ```js run for (let i = 0; i < 3; i++) { // parodo 0, tada 1, tada 2 @@ -121,7 +121,7 @@ Pradedamas vykdymas → ... ``` -Tai yra, `begin` įvykdomas vieną kartą ir tada jis kartojasi (ang. iterates): po kiekvieno `sąlygos` testo, įvykdomi `korpusas` ir `žingsnis`. +Tai yra, `begin` įvykdomas vieną kartą ir tada jis kartojasi (ang. iterates): po kiekvieno `sąlygos` testo įvykdomi `korpusas` ir `žingsnis`. Jeigu ciklai jums naujiena, juos geriau suprasti padėtų , jeigu sugrįžtumėte prie pavyzdžio ir žingsnis po žingsnio atkurtumėte kaip jis veikia ant popieriaus lapo. @@ -141,8 +141,8 @@ if (i < 3) { alert(i); i++ } // ...pabaiga, nes dabar i == 3 ``` -````smart header="Įterptojo kintamojo deklaracija" -Čia "skaičiuojantis" (ang. "counter") kintamasis `i` yra deklaruotas tiesiai cikle. Tai vadinama "įterptojo" (ang. "inline") kintamojo deklaracija. Toks kintamasis yra matomas tik ciklo viduje. +````smart header="Vidinio kintamojo deklaracija" +Čia "skaičiuojantis" (ang. "counter") kintamasis `i` yra deklaruotas tiesiai cikle. Tai vadinama "vidinio" (ang. "inline") kintamojo deklaracija. Toks kintamasis yra matomas tik ciklo viduje. ```js run for (*!*let*/!* i = 0; i < 3; i++) { @@ -160,7 +160,7 @@ for (i = 0; i < 3; i++) { // naudojamas jau egzituojantis kintamasis alert(i); // 0, 1, 2 } -alert(i); // 3, matomas, nes deklaruotas už ciklo ribų +alert(i); // 3, matomas, nes buvo deklaruotas už ciklo ribų ``` ```` @@ -202,7 +202,7 @@ for (;;) { } ``` -Atkreipkite dėmesį, kad du `for` kabliataškiai `;` myra privalomi. Kitu atveju bus sintaksės klaida. +Atkreipkite dėmesį, kad du `for` kabliataškiai `;` yra privalomi. Kitu atveju bus sintaksės klaida. ## Ciklo nutraukimas @@ -254,7 +254,7 @@ for (let i = 0; i < 10; i++) { Lyginėms `i` vertėms, direktyva `continue` nustoja vykdyti korpusą ir perleidžia kontrolę sekančiai `for` iteracijai (su sekančiu skaičiumi). Tad `alert` yra iškviečiamas tik nelyginėms vertėms. ````smart header="Direktyva `continue` sumažina matrioškinį kodą (ang. nesting)" -Ciklas, kuris parodo nelygines vertes gali atrodyti taip: +Ciklas, kuris parodo nelygines vertes gali atrodyti ir taip: ```js for (let i = 0; i < 10; i++) { @@ -266,7 +266,7 @@ for (let i = 0; i < 10; i++) { } ``` -Iš techninės perspektyvos tai yra visiškai identiškas kodas pavyzdžiui aukšąiau. Žinoma, mes galime tiesiog apgobti `if` rinkinį vietoje to, kad naudotume `continue`. +Iš techninės perspektyvos tai yra visiškai identiškas kodas aukščiau esančiam pavyzdžiui. Žinoma, mes galime tiesiog apgobti `if` rinkinį vietoje to, kad naudotume `continue`. Bet to pašalinis efektas yra papildomas matrioškinis lygis (šaukimas `alert` viduje riestinių skliaustų). O jeigu kodas `if` viduje yra ilgesnis nei kelios eilės, tai apsunkina skaitomumą. ```` @@ -288,99 +288,99 @@ if (i > 5) { ```js no-beautify -(i > 5) ? alert(i) : *!*continue*/!*; // continue nėra čią leidžiamas +(i > 5) ? alert(i) : *!*continue*/!*; // continue nėra leidžiamas ``` -...jis nustoja veikti: tai yra sintaksinė klaida. +...jis nustoja veikti: tai yra sintaksės klaida. Tai tik dar viena priežastis nenaudoti klaustuko operatoriaus `?` vietoje`if`. ```` ## Etiketės break/continue -Sometimes we need to break out from multiple nested loops at once. +Kartais mums reikia ištrūkti iš daugybinių matrioškinių ciklų tuo pačiu metu. -For example, in the code below we loop over `i` and `j`, prompting for the coordinates `(i, j)` from `(0,0)` to `(2,2)`: +Pavyzdžiui, kode žemiau mes paleidžiame ciklą per `i` ir `j`, klausdami koordinačių `(i, j)` nuo `(0,0)` iki `(2,2)`: ```js run no-beautify for (let i = 0; i < 3; i++) { for (let j = 0; j < 3; j++) { - let input = prompt(`Value at coords (${i},${j})`, ''); + let input = prompt(`Vertė koordinatėse (${i},${j})`, ''); - // what if we want to exit from here to Done (below)? + // kas nutinka jeigu norime išeiti šiuo momentu iki Baigta (žemiau)? } } -alert('Done!'); +alert('Baigta!'); ``` -We need a way to stop the process if the user cancels the input. +Mums reikia tokio būdo, kuris sustabdytų procesą, jeigu lankytojas atšaukia įvedimą. -The ordinary `break` after `input` would only break the inner loop. That's not sufficient--labels, come to the rescue! +Įprastinis `break` sekantis po `input` sustabdytų tik vidinį ciklą. To neužtenka--į pagalba ateina etiketės! -A *label* is an identifier with a colon before a loop: +*Etikėtė* tai toks identifikatorius su dvitaškiu prieš ciklą: ```js -labelName: for (...) { +etiketėsPavadinimas: for (...) { ... } ``` -The `break ` statement in the loop below breaks out to the label: +Teiginys `break ` cikle žemiau nutraukia procesą iki etiketės: ```js run no-beautify -*!*outer:*/!* for (let i = 0; i < 3; i++) { +*!*išorinis:*/!* for (let i = 0; i < 3; i++) { for (let j = 0; j < 3; j++) { - let input = prompt(`Value at coords (${i},${j})`, ''); + let input = prompt(`Vertė koordinatėse (${i},${j})`, ''); - // if an empty string or canceled, then break out of both loops - if (!input) *!*break outer*/!*; // (*) + // jeigu eilutė tuščia arba buvo atšaukta, nutraukti procesą iš abiejų ciklų + if (!input) *!*break išorinis*/!*; // (*) - // do something with the value... + // darykite kažką su verte... } } -alert('Done!'); +alert('Baigta!'); ``` -In the code above, `break outer` looks upwards for the label named `outer` and breaks out of that loop. +Kodas viršuje `break išorinis` suranda viršuje etiketę su pavadinimu `išorinis` ir nutraukia tą ciklą. -So the control goes straight from `(*)` to `alert('Done!')`. +Tad kontrolė pereina tiesiai nuo `(*)` iki `alert('Baigta!')`. -We can also move the label onto a separate line: +Mes taip pat galime perkelti etiketę į atskirą eilę: ```js no-beautify -outer: +išorinis: for (let i = 0; i < 3; i++) { ... } ``` -The `continue` directive can also be used with a label. In this case, code execution jumps to the next iteration of the labeled loop. +Direktyva `continue` taip pat gali būti naudojama su etiketėmis. Šiuo atveju kodo įvykdymas peršoka prie sekančios ciklo su etikete iteracijos. -````warn header="Labels do not allow to \"jump\" anywhere" -Labels do not allow us to jump into an arbitrary place in the code. +````warn header="Etiketės neleidžia \"peršokti\" bet kur" +Etiketės negali leisti peršokti į bet kurią arbitrišką kodo vietą. -For example, it is impossible to do this: +Pavyzdžiui tai nėra įmanoma: ```js -break label; // doesn't jumps to the label below +break etiketė; // neperšoka į etiketę žemiau -label: for (...) +etiketė: for (...) ``` -A call to `break/continue` is only possible from inside a loop and the label must be somewhere above the directive. +Šaukimas `break/continue` įmanoma tik iš ciklo vidaus ir etiketė turi būti kažkur virš direktyvos. ```` -## Summary +## Santrauka -We covered 3 types of loops: +Mes aptarėme 3 ciklų tipus: -- `while` -- The condition is checked before each iteration. -- `do..while` -- The condition is checked after each iteration. -- `for (;;)` -- The condition is checked before each iteration, additional settings available. +- `while` -- Sąlyga patikrinima prieš kiekvieną iteraciją. +- `do..while` -- Sąlyga patikrinama po kiekvienos iteracijos. +- `for (;;)` -- Sąlyga patikrinama prieš kiekvieną iteraciją, įmanomi papildomi nustatymai. -To make an "infinite" loop, usually the `while(true)` construct is used. Such a loop, just like any other, can be stopped with the `break` directive. +Kad padarytume "begalinį" ciklą, naudojamas konstruktas `while(true)`. Toks ciklas, kaip ir bet kuris kitas, gali būti sustabdytas naudojant direktyvą `break`. -If we don't want to do anything in the current iteration and would like to forward to the next one, we can use the `continue` directive. +Jeigu nenorime nieko daryti esamoje iteracijoje, bet norime pereiti prie sekančios, galime naudoti `continue` direktyvą. -`break/continue` support labels before the loop. A label is the only way for `break/continue` to escape a nested loop to go to an outer one. +`break/continue` palaiko etiketes prieš ciklą. Etiketė yra vienintelis kelias tam, kad `break/continue` išeitų iš matrioškinio vidinio ciklo į išorinį. From 6b23c7fb87bd962c1851aee1be19666020281a73 Mon Sep 17 00:00:00 2001 From: Ginja <30539630+meilune@users.noreply.github.com> Date: Mon, 16 Aug 2021 14:00:40 +1000 Subject: [PATCH 05/19] Translated task.md --- 1-js/02-first-steps/12-while-for/1-loop-last-value/task.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/1-js/02-first-steps/12-while-for/1-loop-last-value/task.md b/1-js/02-first-steps/12-while-for/1-loop-last-value/task.md index 3b847dfa2..4dea36314 100644 --- a/1-js/02-first-steps/12-while-for/1-loop-last-value/task.md +++ b/1-js/02-first-steps/12-while-for/1-loop-last-value/task.md @@ -2,9 +2,9 @@ importance: 3 --- -# Last loop value +# Paskutinė ciklo vertė -What is the last value alerted by this code? Why? +Kokia yra paskutinė šio kodo vertė parodyta per alert? Kodėl? ```js let i = 3; From 4442b7efec38144dde9af5d5885305f3b23282b9 Mon Sep 17 00:00:00 2001 From: Ginja <30539630+meilune@users.noreply.github.com> Date: Mon, 16 Aug 2021 14:12:19 +1000 Subject: [PATCH 06/19] Translated solution.md --- .../12-while-for/1-loop-last-value/solution.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/1-js/02-first-steps/12-while-for/1-loop-last-value/solution.md b/1-js/02-first-steps/12-while-for/1-loop-last-value/solution.md index 43ee4aad3..91354ed54 100644 --- a/1-js/02-first-steps/12-while-for/1-loop-last-value/solution.md +++ b/1-js/02-first-steps/12-while-for/1-loop-last-value/solution.md @@ -1,4 +1,4 @@ -The answer: `1`. +Atsakymas: `1`. ```js run let i = 3; @@ -8,18 +8,18 @@ while (i) { } ``` -Every loop iteration decreases `i` by `1`. The check `while(i)` stops the loop when `i = 0`. +Kiekviena ciklo iteracija sumažina `i` per `1`. Patikrinimas `while(i)` sustabdo ciklą kai `i = 0`. -Hence, the steps of the loop form the following sequence ("loop unrolled"): +Dėl to žingsniai iš paskutinio ciklo suformuoja tokią seką ("atskleistas ciklas"): ```js let i = 3; -alert(i--); // shows 3, decreases i to 2 +alert(i--); // parodo 3, sumažina i iki 2 -alert(i--) // shows 2, decreases i to 1 +alert(i--) // parodo 2, sumažina i iki 1 -alert(i--) // shows 1, decreases i to 0 +alert(i--) // parodo 1, sumažina i iki 0 -// done, while(i) check stops the loop +// viskas, while(i) patikrinimas sustabdo ciklą ``` From 959f2153b504586136279df00549713975cc1703 Mon Sep 17 00:00:00 2001 From: Ginja <30539630+meilune@users.noreply.github.com> Date: Mon, 16 Aug 2021 14:15:48 +1000 Subject: [PATCH 07/19] Translated taks.md --- .../12-while-for/2-which-value-while/task.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/1-js/02-first-steps/12-while-for/2-which-value-while/task.md b/1-js/02-first-steps/12-while-for/2-which-value-while/task.md index 298213237..000bd521a 100644 --- a/1-js/02-first-steps/12-while-for/2-which-value-while/task.md +++ b/1-js/02-first-steps/12-while-for/2-which-value-while/task.md @@ -2,19 +2,19 @@ importance: 4 --- -# Which values does the while loop show? +# Kurias vertes parodo while ciklas? -For every loop iteration, write down which value it outputs and then compare it with the solution. +Kiekvienai ciklo iteracijai užrašykite kurią vertę ji atiduoda ir tada palygininkite tą vertę su sprendimu. -Both loops `alert` the same values, or not? +Abu ciklai `alert` tas pačias vertes ar ne? -1. The prefix form `++i`: +1. Priešdėlinė forma `++i`: ```js let i = 0; while (++i < 5) alert( i ); ``` -2. The postfix form `i++` +2. Podėlinė forma `i++` ```js let i = 0; From 6327f3c1d02a74a10f998f82e200ac87b820579c Mon Sep 17 00:00:00 2001 From: Ginja <30539630+meilune@users.noreply.github.com> Date: Mon, 16 Aug 2021 14:24:38 +1000 Subject: [PATCH 08/19] Translated solution.md --- .../2-which-value-while/solution.md | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/1-js/02-first-steps/12-while-for/2-which-value-while/solution.md b/1-js/02-first-steps/12-while-for/2-which-value-while/solution.md index 495359876..861ff860d 100644 --- a/1-js/02-first-steps/12-while-for/2-which-value-while/solution.md +++ b/1-js/02-first-steps/12-while-for/2-which-value-while/solution.md @@ -1,30 +1,30 @@ -The task demonstrates how postfix/prefix forms can lead to different results when used in comparisons. +Užduotis parodo kaip priešdėlinė/podėlinė formos gali atvesti prie skirtingų rezultatų kai naudojamos palyginimui. -1. **From 1 to 4** +1. **Nuo 1 iki 4** ```js run let i = 0; while (++i < 5) alert( i ); ``` - 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`. + 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`. - Then follow `2, 3, 4…` -- the values show up one after another. The comparison always uses the incremented value, because `++` is before the variable. + Tada seka `2, 3, 4…` -- vertės pasirodo viena po kitos. Palyginimui visada naudojama jau padidinta vertė, nes `++` yra prieš kintamąjį. - Finally, `i = 4` is incremented to `5`, the comparison `while(5 < 5)` fails, and the loop stops. So `5` is not shown. -2. **From 1 to 5** + Galų gale, `i = 4` yra padidinamas iki `5`, tad palyginimas `while(5 < 5)` yra netiesa ir ciklas sustoja. Tad `5` nėra parodomas. +2. **Nuo 1 iki 5** ```js run let i = 0; while (i++ < 5) alert( i ); ``` - 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`). + 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`). - 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`. + Bet šaukimas `alert` yra atskiras, Tai yra kitas teiginys, kuris yra įvykdomas po padidinimo ir palyginimo. Tad jis gauna esamą `i = 1`. - Then follow `2, 3, 4…` + Toliau seka `2, 3, 4…` - 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`. + 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`. - The value `i = 5` is the last one, because on the next step `while(5 < 5)` is false. + Vertė `i = 5` yra paskutinė, nes sekančiame žingsnyje `while(5 < 5)` būtų netiesa. From 62b7b30676abd4d45e7c25c6a879b7fe2bfb1d5e Mon Sep 17 00:00:00 2001 From: Ginja <30539630+meilune@users.noreply.github.com> Date: Mon, 16 Aug 2021 16:02:14 +1000 Subject: [PATCH 09/19] Translated task.md --- .../12-while-for/3-which-value-for/task.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/1-js/02-first-steps/12-while-for/3-which-value-for/task.md b/1-js/02-first-steps/12-while-for/3-which-value-for/task.md index bfefa63f5..3ebdc5e79 100644 --- a/1-js/02-first-steps/12-while-for/3-which-value-for/task.md +++ b/1-js/02-first-steps/12-while-for/3-which-value-for/task.md @@ -2,18 +2,18 @@ importance: 4 --- -# Which values get shown by the "for" loop? +# Korias vertes parodo "for" ciklas? -For each loop write down which values it is going to show. Then compare with the answer. +Kiekvienam ciklui parašykite vertes, kurias jis parodys. Tada palyginkite atsakymus. -Both loops `alert` same values or not? +Abu `alert` ciklai, bet ar tos pačios vertės? -1. The postfix form: +1. Podėlio forma: ```js for (let i = 0; i < 5; i++) alert( i ); ``` -2. The prefix form: +2. Priešdėlio forma: ```js for (let i = 0; i < 5; ++i) alert( i ); From 2893f1ff3fe3ecd5a34b4a89177d2410f7090b86 Mon Sep 17 00:00:00 2001 From: Ginja <30539630+meilune@users.noreply.github.com> Date: Mon, 16 Aug 2021 16:07:14 +1000 Subject: [PATCH 10/19] Translated solution.md --- .../12-while-for/3-which-value-for/solution.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/1-js/02-first-steps/12-while-for/3-which-value-for/solution.md b/1-js/02-first-steps/12-while-for/3-which-value-for/solution.md index e2e28e75b..dc62125a8 100644 --- a/1-js/02-first-steps/12-while-for/3-which-value-for/solution.md +++ b/1-js/02-first-steps/12-while-for/3-which-value-for/solution.md @@ -1,4 +1,4 @@ -**The answer: from `0` to `4` in both cases.** +**Atsakymas: nuo `0` iki `4` abiem atvejais.** ```js run for (let i = 0; i < 5; ++i) alert( i ); @@ -6,12 +6,12 @@ for (let i = 0; i < 5; ++i) alert( i ); for (let i = 0; i < 5; i++) alert( i ); ``` -That can be easily deducted from the algorithm of `for`: +Tai galima labai lengvai nustatyti iš `for` algoritmo: -1. Execute once `i = 0` before everything (begin). -2. Check the condition `i < 5` -3. If `true` -- execute the loop body `alert(i)`, and then `i++` +1. Įvykdyti vieną kartą `i = 0` prieš visa kita (pradžia). +2. Patikrinti sąlygą `i < 5` +3. Jeigu `true` -- įvykdyti ciklo korpusą `alert(i)`, o tada `i++` -The increment `i++` is separated from the condition check (2). That's just another statement. +Padidėjimas `i++` yra atskirtas nuo sąlygos patikrinimo (2). Tai tik dar vienas teiginys. -The value returned by the increment is not used here, so there's no difference between `i++` and `++i`. +Vertė grąžinta padidėjimo nėra čia naudojama, tad nėra jokio skirtumo tarp `i++` ir `++i`. From a39f60ff38a71d1a669d2d8926527d2669c13b29 Mon Sep 17 00:00:00 2001 From: Ginja <30539630+meilune@users.noreply.github.com> Date: Mon, 16 Aug 2021 16:08:57 +1000 Subject: [PATCH 11/19] Translated task.md --- 1-js/02-first-steps/12-while-for/4-for-even/task.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/1-js/02-first-steps/12-while-for/4-for-even/task.md b/1-js/02-first-steps/12-while-for/4-for-even/task.md index ff34e7e40..96a7ecac2 100644 --- a/1-js/02-first-steps/12-while-for/4-for-even/task.md +++ b/1-js/02-first-steps/12-while-for/4-for-even/task.md @@ -2,8 +2,8 @@ importance: 5 --- -# Output even numbers in the loop +# Grąžinkite lyginius skaičius su ciklu -Use the `for` loop to output even numbers from `2` to `10`. +Panaudokite `for` ciklą, kad gautumėte lyginius skaičius nuo `2` iki `10`. [demo] From 9ffe3e67848562e7e49cbcf7388c510e64a1e961 Mon Sep 17 00:00:00 2001 From: Ginja <30539630+meilune@users.noreply.github.com> Date: Mon, 16 Aug 2021 16:10:41 +1000 Subject: [PATCH 12/19] Translated solution.md --- 1-js/02-first-steps/12-while-for/4-for-even/solution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/12-while-for/4-for-even/solution.md b/1-js/02-first-steps/12-while-for/4-for-even/solution.md index e8e66bb47..43171c1e7 100644 --- a/1-js/02-first-steps/12-while-for/4-for-even/solution.md +++ b/1-js/02-first-steps/12-while-for/4-for-even/solution.md @@ -8,4 +8,4 @@ for (let i = 2; i <= 10; i++) { } ``` -We use the "modulo" operator `%` to get the remainder and check for the evenness here. +Mes naudojame "liekanos" operatorių `%`, kad gautume liekaną ir patikrintume lygybę. From a24475cd8470496b26e34c91812d6dd92adf1dc9 Mon Sep 17 00:00:00 2001 From: Ginja <30539630+meilune@users.noreply.github.com> Date: Mon, 16 Aug 2021 16:12:43 +1000 Subject: [PATCH 13/19] Translated task.md --- .../02-first-steps/12-while-for/5-replace-for-while/task.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/1-js/02-first-steps/12-while-for/5-replace-for-while/task.md b/1-js/02-first-steps/12-while-for/5-replace-for-while/task.md index 0c69d9c2d..d0bf15523 100644 --- a/1-js/02-first-steps/12-while-for/5-replace-for-while/task.md +++ b/1-js/02-first-steps/12-while-for/5-replace-for-while/task.md @@ -2,13 +2,13 @@ importance: 5 --- -# Replace "for" with "while" +# Pakeiskite "for" į "while" -Rewrite the code changing the `for` loop to `while` without altering its behavior (the output should stay same). +Perrašykite kodą pakeisdami ciklą `for` į `while`, nepakeisdami elgesio (turėtumėte gauti tą patį atsakymą). ```js run for (let i = 0; i < 3; i++) { - alert( `number ${i}!` ); + alert( `skaičius ${i}!` ); } ``` From 784219fa749c4adfe68a6a9df7e5958dd9bb4846 Mon Sep 17 00:00:00 2001 From: Ginja <30539630+meilune@users.noreply.github.com> Date: Mon, 16 Aug 2021 16:13:31 +1000 Subject: [PATCH 14/19] Translated solution.md --- .../02-first-steps/12-while-for/5-replace-for-while/solution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/12-while-for/5-replace-for-while/solution.md b/1-js/02-first-steps/12-while-for/5-replace-for-while/solution.md index 612cf559c..53b721d21 100644 --- a/1-js/02-first-steps/12-while-for/5-replace-for-while/solution.md +++ b/1-js/02-first-steps/12-while-for/5-replace-for-while/solution.md @@ -3,7 +3,7 @@ ```js run let i = 0; while (i < 3) { - alert( `number ${i}!` ); + alert( `skaičius ${i}!` ); i++; } ``` From ca574552c40e13d57415290fdfa3f5cbd2c07634 Mon Sep 17 00:00:00 2001 From: Ginja <30539630+meilune@users.noreply.github.com> Date: Mon, 16 Aug 2021 16:18:10 +1000 Subject: [PATCH 15/19] Translated task.md --- .../12-while-for/6-repeat-until-correct/task.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/1-js/02-first-steps/12-while-for/6-repeat-until-correct/task.md b/1-js/02-first-steps/12-while-for/6-repeat-until-correct/task.md index 0788ee76e..82f275cba 100644 --- a/1-js/02-first-steps/12-while-for/6-repeat-until-correct/task.md +++ b/1-js/02-first-steps/12-while-for/6-repeat-until-correct/task.md @@ -2,12 +2,12 @@ importance: 5 --- -# Repeat until the input is correct +# Kartoti kol įvestis bus teisinga -Write a loop which prompts for a number greater than `100`. If the visitor enters another number -- ask them to input again. +Parašykite ciklą, kurios prašytų skaičių didesnio už `100`. Jeigu lankytojas įveda kitokį skaičių -- paprašykite dar kartą įvesti. -The loop must ask for a number until either the visitor enters a number greater than `100` or cancels the input/enters an empty line. +Ciklas turi prašyti skaičio tol kol lankytojas įves skaičių didesnį nei `100` arba atšauks (ang. cancels) įvestį arba paliks tuščią eilutę paspausdamas enter. -Here we can assume that the visitor only inputs numbers. There's no need to implement a special handling for a non-numeric input in this task. +Čia galime numanyti, kad lankytojas ves tik skaičius. Nėra reikalo atskirai pasirūpinti neskaitine užduoties įvestimi. [demo] From 37e6ccbde6bd678ad346c65afb29a245d89bd1a2 Mon Sep 17 00:00:00 2001 From: Ginja <30539630+meilune@users.noreply.github.com> Date: Mon, 16 Aug 2021 16:41:13 +1000 Subject: [PATCH 16/19] Translated solution.md --- .../12-while-for/6-repeat-until-correct/solution.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/1-js/02-first-steps/12-while-for/6-repeat-until-correct/solution.md b/1-js/02-first-steps/12-while-for/6-repeat-until-correct/solution.md index 2e04a78c4..af771bd34 100644 --- a/1-js/02-first-steps/12-while-for/6-repeat-until-correct/solution.md +++ b/1-js/02-first-steps/12-while-for/6-repeat-until-correct/solution.md @@ -3,13 +3,13 @@ let num; do { - num = prompt("Enter a number greater than 100?", 0); + num = prompt("Įveskite skaičių didesnį nei 100?", 0); } while (num <= 100 && num); ``` -The loop `do..while` repeats while both checks are truthy: +Ciklas`do..while` pakartoja kol abu patikrinimai yra truthy: -1. The check for `num <= 100` -- that is, the entered value is still not greater than `100`. -2. The check `&& num` is false when `num` is `null` or a empty string. Then the `while` loop stops too. +1. Patikrinimas dėl `num <= 100` -- tai yra, įvesta vertė vis dar nėra didesnė už `100`. +2. Patikrinimas `&& num` yra neteisingas, jeigu `num` yra `null` arba tuščia eilutė. Tada `while` ciklas taip pat sustoja. -P.S. If `num` is `null` then `num <= 100` is `true`, so without the 2nd check the loop wouldn't stop if the user clicks CANCEL. Both checks are required. +P.S. Jeigu `num` yra `null` tada `num <= 100` yra `true`, tad be antro patikrinimo ciklas nesustotų, jeigu lankytojas paspaustų CANCEL. Abu patikrinimai yra reikalingi. From 08f0076d28353a6d2e6b54bde5095b394a8fd071 Mon Sep 17 00:00:00 2001 From: Ginja <30539630+meilune@users.noreply.github.com> Date: Mon, 16 Aug 2021 16:46:16 +1000 Subject: [PATCH 17/19] Translated task.md --- .../12-while-for/7-list-primes/task.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/1-js/02-first-steps/12-while-for/7-list-primes/task.md b/1-js/02-first-steps/12-while-for/7-list-primes/task.md index 6344b9f6f..ddb19c696 100644 --- a/1-js/02-first-steps/12-while-for/7-list-primes/task.md +++ b/1-js/02-first-steps/12-while-for/7-list-primes/task.md @@ -2,16 +2,16 @@ importance: 3 --- -# Output prime numbers +# Atiduoti pirminius numerius -An integer number greater than `1` is called a [prime](https://en.wikipedia.org/wiki/Prime_number) if it cannot be divided without a remainder by anything except `1` and itself. +Sveikieji skaičiai didesni už `1` yra vadinami [prime](https://en.wikipedia.org/wiki/Prime_number), jeigu jie gali būti padalinti be liekanos tik iš pačio savęs arba `1`. -In other words, `n > 1` is a prime if it can't be evenly divided by anything except `1` and `n`. +Kitaip sakant, `n > 1` yra pirminis, jeigu jis negali būti lygiai padalintas iš nieko kitaip kaip tik `1` ir `n`. -For example, `5` is a prime, because it cannot be divided without a remainder by `2`, `3` and `4`. +Pavyzdžiui, `5` yra pirminis, nes negali būti padalintas be liekanos iš `2`, `3` ir `4`. -**Write the code which outputs prime numbers in the interval from `2` to `n`.** +**Parašykite kodą, kuris atiduotų pirminius numerius intervalu tarp `2` iki `n`.** -For `n = 10` the result will be `2,3,5,7`. +Šiuo atveju `n = 10` rezultatas būtų `2,3,5,7`. -P.S. The code should work for any `n`, not be hard-tuned for any fixed value. +P.S. Kodas turi veikti bet kuriam `n`, o ne paruoštas atitinkamoms vertėms. From 17290c5384f84858f68e3959aa39bff6da0e0e33 Mon Sep 17 00:00:00 2001 From: Ginja <30539630+meilune@users.noreply.github.com> Date: Mon, 16 Aug 2021 17:04:10 +1000 Subject: [PATCH 18/19] Translated solution.md --- .../12-while-for/7-list-primes/solution.md | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/1-js/02-first-steps/12-while-for/7-list-primes/solution.md b/1-js/02-first-steps/12-while-for/7-list-primes/solution.md index b4b64b6fa..9ee6dcb5a 100644 --- a/1-js/02-first-steps/12-while-for/7-list-primes/solution.md +++ b/1-js/02-first-steps/12-while-for/7-list-primes/solution.md @@ -1,29 +1,29 @@ -There are many algorithms for this task. +Yra daug algoritmų šiai užduočiai. -Let's use a nested loop: +Panaudokime matrioškinį ciklą: ```js -For each i in the interval { - check if i has a divisor from 1..i - if yes => the value is not a prime - if no => the value is a prime, show it +Kiekvienam i intervale { + patikrinkite ar i turi daliklį iš 1..i + jeigu taip => vertė nėra pirminius skaičius + jeigu ne => vertė yra pirminis skaičius, parodykite ją } ``` -The code using a label: +Kodas naudojant etiketę: ```js run let n = 10; nextPrime: -for (let i = 2; i <= n; i++) { // for each i... +for (let i = 2; i <= n; i++) { // kiekvienam i... - for (let j = 2; j < i; j++) { // look for a divisor.. - if (i % j == 0) continue nextPrime; // not a prime, go next i + for (let j = 2; j < i; j++) { // ieškoti daliklio.. + if (i % j == 0) tęsti nextPrime; // ne pirminis skaičius, eiti prie sekančio i } - alert( i ); // a prime + alert( i ); // pirminis } ``` -There's a lot of space to optimize it. For instance, we could look for the divisors from `2` to square root of `i`. But anyway, if we want to be really efficient for large intervals, we need to change the approach and rely on advanced maths and complex algorithms like [Quadratic sieve](https://en.wikipedia.org/wiki/Quadratic_sieve), [General number field sieve](https://en.wikipedia.org/wiki/General_number_field_sieve) etc. +Yra daug vietos, kur galima jį optimizuoti. Pavyzdžiui, galėtume ieškoti daliklių nuo `2` iki `i` šaknies. Bet kokiu atveju, jeigu norime būti efektyvūs dideliems intervalams, reikia pakeisti priėjimo būdus ir pasitikėti pažengusia matematika ir sudėtingais algoritmais kaip [Quadratic sieve](https://en.wikipedia.org/wiki/Quadratic_sieve), [General number field sieve](https://en.wikipedia.org/wiki/General_number_field_sieve) etc. From f033939285cb1b274c25d79b66bb0d093f64432c Mon Sep 17 00:00:00 2001 From: Ginja <30539630+meilune@users.noreply.github.com> Date: Mon, 16 Aug 2021 17:04:39 +1000 Subject: [PATCH 19/19] Translated solution.md --- 1-js/02-first-steps/12-while-for/7-list-primes/solution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/12-while-for/7-list-primes/solution.md b/1-js/02-first-steps/12-while-for/7-list-primes/solution.md index 9ee6dcb5a..9fd05d7a0 100644 --- a/1-js/02-first-steps/12-while-for/7-list-primes/solution.md +++ b/1-js/02-first-steps/12-while-for/7-list-primes/solution.md @@ -5,7 +5,7 @@ Panaudokime matrioškinį ciklą: ```js Kiekvienam i intervale { patikrinkite ar i turi daliklį iš 1..i - jeigu taip => vertė nėra pirminius skaičius + jeigu taip => vertė nėra pirminis skaičius jeigu ne => vertė yra pirminis skaičius, parodykite ją } ```