- Notifications
You must be signed in to change notification settings - Fork179
Loops tasks#190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Loops tasks#190
Changes fromall commits
Commits
Show all changes
5 commits Select commitHold shift + click to select a range
c645df0
Translate tasks for article 'While For'
tarasyyyk0953183
Update 1-js/02-first-steps/13-while-for/2-which-value-while/solution.md
tarasyyykb36aaca
Update 1-js/02-first-steps/13-while-for/5-replace-for-while/task.md
tarasyyyka22c4c5
Update 1-js/02-first-steps/13-while-for/3-which-value-for/task.md
tarasyyyk6645f39
Update 1-js/02-first-steps/13-while-for/2-which-value-while/task.md
tarasyyykFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
14 changes: 7 additions & 7 deletions1-js/02-first-steps/13-while-for/1-loop-last-value/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
22 changes: 11 additions & 11 deletions1-js/02-first-steps/13-while-for/2-which-value-while/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
Завдання демонструє, як префіксна/постфіксна форми можуть призвести до різних результатів при їх порівнянні. | ||
1.Перший цикл виведе числа **від 1до 4** | ||
```js run | ||
let i = 0; | ||
while (++i < 5) alert( i ); | ||
``` | ||
Перше значення`i = 1`,тому що операція`++i`спочатку збільшує `i`, і після цього повертає *нове* значення. Відповідно, перше порівняння буде`1 < 5`і`alert`виведе `1`. | ||
Далі йдуть `2, 3, 4…` --значення показуються одне за одним. Порівняння завжди відбувається зі збільшеним значенням, тому що`++`стоїть перед змінною. | ||
Наприкінці, коли`i = 4`збільшується до`5`,умова`while(5 < 5)`не справджується, і в результаті цикл зупиняється. Отже, `5`не покажеться. | ||
2.Другий цикл виведе числа **від 1до 5** | ||
```js run | ||
let i = 0; | ||
while (i++ < 5) alert( i ); | ||
``` | ||
Перше значення знову`i = 1`.Постфіксна форма`i++`збільшує `i`до `1` і повертає *старе* значення, тому порівняння`i++ < 5`буде виконуватися з`i = 0` (на противагу `++i < 5`). | ||
Далі йде виклик`alert`. Однак, це вже інший вираз, який виконується після збільшення `i` та порівняння. Тому він отримає поточне значення `i = 1`. | ||
Далі слідують `2, 3, 4…`. | ||
Зупинимося на`i = 4`.Префіксна форма`++i`збільшила б `i` до`5`і використала це значення в порівнянні. Проте ми маємо постфіксну форму`i++`.Отже, вона збільшить `i`до `5`,але поверне старе значення. Таким чином порівняння буде`while(4 < 5)` --що вірно, а тому відбудеться виклик `alert`. | ||
Значення`i = 5`буде останнім, тому що наступний крок вже буде`while(5 < 5)`-- що не вірно. |
10 changes: 5 additions & 5 deletions1-js/02-first-steps/13-while-for/2-which-value-while/task.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
14 changes: 7 additions & 7 deletions1-js/02-first-steps/13-while-for/3-which-value-for/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
**Відповідь: обидва цикли виведуть від`0`до `4`.** | ||
```js run | ||
for (let i = 0; i < 5; ++i) alert( i ); | ||
for (let i = 0; i < 5; i++) alert( i ); | ||
``` | ||
Такий результат обумовлений алгоритмом роботи `for`: | ||
1.Перед виконанням циклу, присвоїти`i = 0`(початок). | ||
2.Перевірити умову`i < 5`. | ||
3.Якщо `true` --виконати тіло циклу: викликати `alert(i)`,а потім `i++`. | ||
Збільшення`i++`виконується окремо від перевірки умови (2 крок).Це інша інструкція. | ||
Значення `i` після збільшення тут не використовується, тому немає різниці між`i++`та `++i`. |
10 changes: 5 additions & 5 deletions1-js/02-first-steps/13-while-for/3-which-value-for/task.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion1-js/02-first-steps/13-while-for/4-for-even/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions1-js/02-first-steps/13-while-for/4-for-even/task.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -2,8 +2,8 @@ importance: 5 | ||
--- | ||
#Виведіть парні числа | ||
Виведіть парні числа від`2`до `10`, використовуючи цикл `for`. | ||
[demo] |
2 changes: 1 addition & 1 deletion1-js/02-first-steps/13-while-for/5-replace-for-while/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -3,7 +3,7 @@ | ||
```js run | ||
let i = 0; | ||
while (i < 3) { | ||
alert( `число ${i}!` ); | ||
i++; | ||
} | ||
``` | ||
6 changes: 3 additions & 3 deletions1-js/02-first-steps/13-while-for/5-replace-for-while/task.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions1-js/02-first-steps/13-while-for/6-repeat-until-correct/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions1-js/02-first-steps/13-while-for/6-repeat-until-correct/task.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
24 changes: 12 additions & 12 deletions1-js/02-first-steps/13-while-for/7-list-primes/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,29 @@ | ||
Є багато способів для вирішення цієї задачі. | ||
Скористаймося вкладеними циклами: | ||
```js | ||
Для кожного `i` в інтервалі (від 2 до n) { | ||
перевірити, чи число `i` має дільник з діапазону 2..i | ||
якщо так =>значення не просте | ||
якщо ні =>значення просте, показати його | ||
} | ||
``` | ||
Код з використанням мітки: | ||
```js run | ||
let n = 10; | ||
nextPrime: | ||
for (let i = 2; i <= n; i++) { //для кожного i... | ||
for (let j = 2; j < i; j++) { //шукаємо дільник.. | ||
if (i % j == 0) continue nextPrime; //не просте, беремо наступне i | ||
} | ||
alert( i ); //просте число | ||
} | ||
``` | ||
Звичайно, цей код можна оптимізувати з точки зору продуктивності. Наприклад, ми могли б перевіряти всі `j` від `2`до квадратного кореня з `i`.Але все ж таки, якби потрібно було перебирати справді великі числа, нам прийшлося б використовувати просунуту математику і складні алгоритми на кшталт [квадратичного решета](https://uk.wikipedia.org/wiki/Квадратичне_решето) чи [методу решета числового поля](https://uk.wikipedia.org/wiki/Метод_решета_числового_поля). |
14 changes: 7 additions & 7 deletions1-js/02-first-steps/13-while-for/7-list-primes/task.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.