From 665e39260570075bebe488880bbc10a07a4bbc87 Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Sun, 28 Mar 2021 14:27:01 +0430 Subject: [PATCH 01/23] Fix typos MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit line 11: `i++` -> `++i` because it is `پیشوند` line 18: `++i` -> `i++` because it is `پسوند` --- 1-js/02-first-steps/13-while-for/2-which-value-while/task.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/1-js/02-first-steps/13-while-for/2-which-value-while/task.md b/1-js/02-first-steps/13-while-for/2-which-value-while/task.md index e8c1ea4e9..dd980046c 100644 --- a/1-js/02-first-steps/13-while-for/2-which-value-while/task.md +++ b/1-js/02-first-steps/13-while-for/2-which-value-while/task.md @@ -8,14 +8,14 @@ importance: 4 هر دو حلقه، مقادیر یکسانی را `alert` میکنند یا خیر؟ -1. حالت پیشوند `i++`: +1. حالت پیشوند `++i`: ```js let i = 0; while (++i < 5) alert( i ); ``` -2. حالت پسوند `++i`: +2. حالت پسوند `i++`: ```js let i = 0; From 8e5707f8c4d026edd7997b4d06f87eaf11dbbe1a Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Sun, 28 Mar 2021 14:56:54 +0430 Subject: [PATCH 02/23] Translate solution.md of " 2-which-value-while" Please review and comment / commit if anything is wrong --- .../2-which-value-while/solution.md | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/1-js/02-first-steps/13-while-for/2-which-value-while/solution.md b/1-js/02-first-steps/13-while-for/2-which-value-while/solution.md index 495359876..ae9683445 100644 --- a/1-js/02-first-steps/13-while-for/2-which-value-while/solution.md +++ b/1-js/02-first-steps/13-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. +تمرین نشان می دهد که چگونه شکل های پسوند/پیشوند می توانند باعث نتایج متفاوت بشوند وقتی که در مقایسه ها استفاده می شوند. -1. **From 1 to 4** +1. **از 1 تا 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`. + مقدار اول `i = 1` است، چون `++i` اول `i` را افزایش می دهد و سپس مقدار جدید را بر می گرداند. پس مقایسه اول `5 < 1` است و `alert` مقدار `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. + سپس `...4 ،3 ،2` -- مقدارها یکی پس از دیگری نمایان می شوند. مقایسه همیشه از مقدار افزایش یافته استفاده می کند، چون `++` قبل از متغیر است. - 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** + در نهایت، `i = 4` است که به `5` افزایش پیدا می کند، مقایسه `while(5 < 5)` شکست می خورد، و حلقه متوقف می شود. بنابراین `5` نمایش داده نمی شود. +2. **از 1 تا 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`). + اولین مقدار باز هم `i = 1` است. شکل پسوند `i++` `i` را افزایش می دهد و سپس مقدار *قدیمی* را بر می گرداند، بنابراین مقایسه `i++ < 5` از `i = 0` استفاده خواهد کرد (متضاد `++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`. + اما صدا زدن `alert` جداگانه است. آن یک دستور دیگر است که بعد از افزایش و مقایسه اجرا می شود. پس `i = 1` را دریافت می کند. - Then follow `2, 3, 4…` + سپس `...4 ،3 ،2` + + بیایید روی `i = 4` متوقف شویم. شکل پیشوند `++i` آن را افزایش می دهد و از `5` در مقایسه استفاده می کند. اما اینجا ما شکل پسوند `i++` را داریم. پس `i` را به `5` افزایش می دهد، اما مقدار قدیمی را بر می گرداند. به این دلیل مقایسه در واقع `while(4 < 5)` است -- درست است، و کنترل به دست `alert` می افتد. - 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`. - - The value `i = 5` is the last one, because on the next step `while(5 < 5)` is false. + مقدار `i = 5` آخرین مقدار است، زیرا در مرحله بعد `while(5 < 5)` اشتباه می شود. From c998f25c10304d06af0bc63a98a5576ade80d83d Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Sun, 28 Mar 2021 15:19:51 +0430 Subject: [PATCH 03/23] Translate task.md of "3-which-value-for" Please review and comment / commit if anything is wrong --- .../13-while-for/3-which-value-for/task.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/1-js/02-first-steps/13-while-for/3-which-value-for/task.md b/1-js/02-first-steps/13-while-for/3-which-value-for/task.md index bfefa63f5..35ebc539b 100644 --- a/1-js/02-first-steps/13-while-for/3-which-value-for/task.md +++ b/1-js/02-first-steps/13-while-for/3-which-value-for/task.md @@ -2,18 +2,18 @@ importance: 4 --- -# Which values get shown by the "for" loop? +# کدام مقدارها توسط حلقه "for" نمایش داده می شوند؟ -For each loop write down which values it is going to show. Then compare with the answer. +برای هر حلقه یادداشت کنید که چه مقداری را نمایش خواهد داد. سپس با جواب مقایسه کنید. -Both loops `alert` same values or not? +هر دو حلقه مقدارهای مشابه را `alert` می کنند یا نه؟ -1. The postfix form: +1. شکل پسوند: ```js for (let i = 0; i < 5; i++) alert( i ); ``` -2. The prefix form: +2. شکل پیشوند: ```js for (let i = 0; i < 5; ++i) alert( i ); From fc9698a831cdad9651007047ae8361f97c2d71ca Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Sun, 28 Mar 2021 15:30:13 +0430 Subject: [PATCH 04/23] Translate task.md of "3-which-value-for" Please review and comment / commit if anything is wrong --- .../13-while-for/3-which-value-for/solution.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/1-js/02-first-steps/13-while-for/3-which-value-for/solution.md b/1-js/02-first-steps/13-while-for/3-which-value-for/solution.md index e2e28e75b..e99416cfa 100644 --- a/1-js/02-first-steps/13-while-for/3-which-value-for/solution.md +++ b/1-js/02-first-steps/13-while-for/3-which-value-for/solution.md @@ -1,4 +1,4 @@ -**The answer: from `0` to `4` in both cases.** +**جواب: از 0 تا 4 در هر دو مورد** ```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`: +می توان به آسانی از الگوریتم `for` آن را فهمید: -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. یک بار `i = 0` را قبل از هر چیزی اجرا می کند(در شروع). +2. شرط `i < 5` را بررسی می کند +3. اگر `true` باشد -- بدنه ی حلقه `alert(i)` اجرا می شود، و سپس `i++` -The increment `i++` is separated from the condition check (2). That's just another statement. +افزایش `i++` از بررسی شرط جداگانه است(2). آن فقط یک دستور جدا است. -The value returned by the increment is not used here, so there's no difference between `i++` and `++i`. +مقدار برگردانده شده توسط increment اینجا استفاده نمی شود، پس تفاوتی بین `i++` و `++i` نیست. From 8eb82e7e4cc5ccf8ae9d00f59267847d52b1ee90 Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Sun, 28 Mar 2021 15:31:40 +0430 Subject: [PATCH 05/23] Translate solution.md of "3-which-value-for" Please review and comment / commit if anything is wrong --- 1-js/02-first-steps/13-while-for/3-which-value-for/solution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/13-while-for/3-which-value-for/solution.md b/1-js/02-first-steps/13-while-for/3-which-value-for/solution.md index e99416cfa..6e23b51d4 100644 --- a/1-js/02-first-steps/13-while-for/3-which-value-for/solution.md +++ b/1-js/02-first-steps/13-while-for/3-which-value-for/solution.md @@ -14,4 +14,4 @@ for (let i = 0; i < 5; i++) alert( i ); افزایش `i++` از بررسی شرط جداگانه است(2). آن فقط یک دستور جدا است. -مقدار برگردانده شده توسط increment اینجا استفاده نمی شود، پس تفاوتی بین `i++` و `++i` نیست. +مقدار برگردانده شده توسط increment اینجا استفاده نمی شود، پس تفاوتی بین `i++` و `++i` نیست. From b61cbbe16e2c0b1b3495aac9753cc7c0f1b47cf6 Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Sun, 28 Mar 2021 18:25:26 +0430 Subject: [PATCH 06/23] Translate task.md of "4-for-even" Please review and comment / commit if anything is wrong --- 1-js/02-first-steps/13-while-for/4-for-even/task.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/1-js/02-first-steps/13-while-for/4-for-even/task.md b/1-js/02-first-steps/13-while-for/4-for-even/task.md index ff34e7e40..69a1ac4b9 100644 --- a/1-js/02-first-steps/13-while-for/4-for-even/task.md +++ b/1-js/02-first-steps/13-while-for/4-for-even/task.md @@ -2,8 +2,8 @@ importance: 5 --- -# Output even numbers in the loop +# اعداد زوج را در حلقه خروجی بدهید -Use the `for` loop to output even numbers from `2` to `10`. +از حلقه `for` برای خروجی دادن اعداد زوج بین `2` و `10` استفاده کنید. -[demo] +[دمو] From 7930ad0c1e8189117ad07bd23f878b7c723e2dd9 Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Sun, 28 Mar 2021 18:29:50 +0430 Subject: [PATCH 07/23] Translate solution.md of "4-for-even" Please review and comment / commit if anything is wrong --- 1-js/02-first-steps/13-while-for/4-for-even/solution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/13-while-for/4-for-even/solution.md b/1-js/02-first-steps/13-while-for/4-for-even/solution.md index e8e66bb47..ebf043aa3 100644 --- a/1-js/02-first-steps/13-while-for/4-for-even/solution.md +++ b/1-js/02-first-steps/13-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. +ما اینجا از عملگر "modulo" `%` برای گرفتن باقی مانده و بررسی زوج بودن استفاده می کنیم. From 77fc525a151bc04a1289f6de8bfeeb7fbbe57cc9 Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Sun, 28 Mar 2021 18:34:25 +0430 Subject: [PATCH 08/23] Translate task.md of "5-replace-for-while" Please review and comment / commit if anything is wrong --- .../02-first-steps/13-while-for/5-replace-for-while/task.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/1-js/02-first-steps/13-while-for/5-replace-for-while/task.md b/1-js/02-first-steps/13-while-for/5-replace-for-while/task.md index 0c69d9c2d..f4924b3d5 100644 --- a/1-js/02-first-steps/13-while-for/5-replace-for-while/task.md +++ b/1-js/02-first-steps/13-while-for/5-replace-for-while/task.md @@ -2,13 +2,13 @@ importance: 5 --- -# Replace "for" with "while" +# "for" را با "while" جایگزین کنید -Rewrite the code changing the `for` loop to `while` without altering its behavior (the output should stay same). +کد را با تغییر حلقه `for` به `while` بدون عوض کردن رفتار آن دوباره بنویسید (خروجی باید یکسان بماند). ```js run for (let i = 0; i < 3; i++) { - alert( `number ${i}!` ); + alert( `عدد ${i}!` ); } ``` From 2a417e31ce5072ece2eced2e69781f8f26276395 Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Sun, 28 Mar 2021 18:35:30 +0430 Subject: [PATCH 09/23] Translate solution.md of "5-replace-for-while" --- .../02-first-steps/13-while-for/5-replace-for-while/solution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/13-while-for/5-replace-for-while/solution.md b/1-js/02-first-steps/13-while-for/5-replace-for-while/solution.md index 612cf559c..e2424b1cb 100644 --- a/1-js/02-first-steps/13-while-for/5-replace-for-while/solution.md +++ b/1-js/02-first-steps/13-while-for/5-replace-for-while/solution.md @@ -3,7 +3,7 @@ ```js run let i = 0; while (i < 3) { - alert( `number ${i}!` ); + alert( `عدد ${i}!` ); i++; } ``` From 979c0314d89d3149b27c72e45563c741ff7c2e13 Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Sun, 28 Mar 2021 18:43:40 +0430 Subject: [PATCH 10/23] Translate task.md of "6-repeat-until-correct" Please review and comment / commit if anything is wrong --- .../13-while-for/6-repeat-until-correct/task.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/1-js/02-first-steps/13-while-for/6-repeat-until-correct/task.md b/1-js/02-first-steps/13-while-for/6-repeat-until-correct/task.md index 0788ee76e..2262538e9 100644 --- a/1-js/02-first-steps/13-while-for/6-repeat-until-correct/task.md +++ b/1-js/02-first-steps/13-while-for/6-repeat-until-correct/task.md @@ -2,12 +2,12 @@ importance: 5 --- -# Repeat until the input is correct +# تا زمانی که ورودی درست باشد تکرار کنید -Write a loop which prompts for a number greater than `100`. If the visitor enters another number -- ask them to input again. +یک حلقه بنویسید که برای یک عدد بزرگ تر از `100` prompt می کند. اگر بازدیدکننده عدد دیگری وارد کرد -- دوباره از او بخواهید که وارد کند. -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. +حلقه باید برای یک عدد درخواست کند مگر اینکه بازدیدکننده یک عدد بزرگ تر از `100` وارد کند یا ورودی گرفتن را لغو کند / یک خط خالی وارد کند. -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. +اینجا ما می توانیم فرض کنیم که بازدیدکننده فقط عدد وارد می کند. در این تمرین نیازی به پیاده سازی بررسی خاصی برای ورودی غیر عددی نیست. -[demo] +[دمو] From 5794364363079ddfe55bdb0e762738def0f29568 Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Sun, 28 Mar 2021 18:51:44 +0430 Subject: [PATCH 11/23] Translate solution.md of "6-repeat-until-correct" Please review and comment / commit if anything is wrong --- .../13-while-for/6-repeat-until-correct/solution.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/1-js/02-first-steps/13-while-for/6-repeat-until-correct/solution.md b/1-js/02-first-steps/13-while-for/6-repeat-until-correct/solution.md index c7de5f09b..f32d6e19b 100644 --- a/1-js/02-first-steps/13-while-for/6-repeat-until-correct/solution.md +++ b/1-js/02-first-steps/13-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("عددی بزرگ تر از 100 وارد کنید.", 0); } while (num <= 100 && num); ``` -The loop `do..while` repeats while both checks are truthy: +حلقه `do..while` تا زمانی که هر دو بررسی 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 an empty string. Then the `while` loop stops too. +1. بررسی `num <= 100` -- به این معنی است که مقدار وارد شده هنوز از `100` بزرگ تر نیست. +2. بررسی `&& num` زمانی که `num` برابر با `null` یا یک رشته خالی باشد اشتباه است. سپس حلقه `while` هم متوقف می شود. -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. +ضمیمه: اگر `num` برابر با `null` باشد سپس `num <= 100` برابر با `true` است، پس بدون بررسی دوم اگر کاربر روی CANCEL کلیک کند حلقه متوقف نمی شود. هر دو بررسی مورد نیاز هستند. From 478e29c5885c3f86b0bdea9f5ed6b222124891ff Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Sun, 28 Mar 2021 19:21:44 +0430 Subject: [PATCH 12/23] Translate task.md (read description) I'm not sure of line 17 translation. Please review and comment / commit if it could be better or anything is wrong --- .../13-while-for/7-list-primes/task.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/1-js/02-first-steps/13-while-for/7-list-primes/task.md b/1-js/02-first-steps/13-while-for/7-list-primes/task.md index 6344b9f6f..b52d3693f 100644 --- a/1-js/02-first-steps/13-while-for/7-list-primes/task.md +++ b/1-js/02-first-steps/13-while-for/7-list-primes/task.md @@ -2,16 +2,16 @@ importance: 3 --- -# Output prime numbers +# اعداد اول را خروجی بدهید -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. +یک عدد صحیح بزرگ تر از 1 زمانی [اول](https://fa.wikipedia.org/wiki/عدد_اول) صدا زده می شود که نتوان آن را به هر چیزی بدون اینکه باقی مانده داشته باشد تقسیم کرد به جز `1` و خودش. -In other words, `n > 1` is a prime if it can't be evenly divided by anything except `1` and `n`. +به عبارتی دیگر، `n > 1` یک عدد اول است اگر نتواند با هیچ چیزی به جز `1` و `n` به صورت مساوی تقسیم شود. -For example, `5` is a prime, because it cannot be divided without a remainder by `2`, `3` and `4`. +برای مثال، `5` یک عدد اول است، چون نمی تواند بدون باقی مانده به `2`، `3` و `4` تقسیم شود. -**Write the code which outputs prime numbers in the interval from `2` to `n`.** +**کدی بنویسید که اعداد اول را در بازه `2` تا `n` خروجی بدهد** -For `n = 10` the result will be `2,3,5,7`. +برای `n = 10` نتیجه `7 ،5 ،3 ،2` خواهد بود. -P.S. The code should work for any `n`, not be hard-tuned for any fixed value. +ضمیمه: کد باید برای هر مقدار `n` کار کند، نه اینکه برای مقدار مشخصی تنظیم شده باشد. From 2d7c86016ba43df59a4f29534abed3a8d25c5bb5 Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Mon, 29 Mar 2021 13:29:01 +0430 Subject: [PATCH 13/23] Translate first part of article.md --- 1-js/02-first-steps/13-while-for/article.md | 36 ++++++++++----------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/1-js/02-first-steps/13-while-for/article.md b/1-js/02-first-steps/13-while-for/article.md index 56a59850a..7b30a8a0c 100644 --- a/1-js/02-first-steps/13-while-for/article.md +++ b/1-js/02-first-steps/13-while-for/article.md @@ -1,54 +1,54 @@ -# Loops: while and for +# حلقه ها: while و for -We often need to repeat actions. +ما معمولا نیاز داریم که کارها رو تکرار کنیم. -For example, outputting goods from a list one after another or just running the same code for each number from 1 to 10. +برای مثال، از یک لیست کالاها را یکی پس از دیگری نمایش دهیم یا کد مشابهی رو برای هر عدد از 1 تا 10 اجرا کنیم. -*Loops* are a way to repeat the same code multiple times. +*حلقه ها* راهی برای تکرار یک کد برای چندین بار هستند. -## The "while" loop +## حلقه "while" -The `while` loop has the following syntax: +حلقه `while` سینتکس زیر را دارد: ```js while (condition) { - // code - // so-called "loop body" + // کد + // به اصطلاح "بدنه حلقه" } ``` -While the `condition` is truthy, the `code` from the loop body is executed. +تا وقتی که `condition` برابر با truthy باشد، `کد` قسمت بدنه حلقه اجرا می شود. -For instance, the loop below outputs `i` while `i < 3`: +برای مثال، حلقه پایین `i` را نمایش می دهد تا وقتی که `i < 3`: ```js run let i = 0; -while (i < 3) { // shows 0, then 1, then 2 +while (i < 3) { // 0 را نمایش می دهد، سپس 1، سپس 2 alert( i ); i++; } ``` -A single execution of the loop body is called *an iteration*. The loop in the example above makes three iterations. +یک بار اجرا شدن بدنه حلقه *یک تکرار* نامیده می شود. حلقه داخل مثال بالا سه تکرار می سازد. -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. +اگر `i++` از مثال بالا جا می ماند، حلقه (در تئوری) برای همیشه اجرا می شد. در عمل، مرورگر راه هایی را برای متوقف کردن چنین حلقه هایی مهیا می کند، و در جاوااسکریپت سمت سرور، ما می توانیم فرایند را نابود کنیم. -Any expression or variable can be a loop condition, not just comparisons: the condition is evaluated and converted to a boolean by `while`. +هر عبارت یا متغیری می تواند یک شرط حلقه باشد، نه فقط مقایسه ها: شرط توسط `while` ارزیابی می شود و به boolean تبدیل می شود. -For instance, a shorter way to write `while (i != 0)` is `while (i)`: +برای مثال، یک راه کوتاه تر برای نوشتن `while (i != 0)` `while (i)` است: ```js run let i = 3; *!* -while (i) { // when i becomes 0, the condition becomes falsy, and the loop stops +while (i) { // وقتی که i برابر با 0 شود، شرط falsy می شود، و حلقه متوقف می شود */!* 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="آکولادها برای بدنه تک خطی الزامی نیستند" +اگر بدنه حلقه یک دستور واحد داشته باشد، ما می توانیم آکولادها `{...}` را حذف کنیم: ```js run let i = 3; From d702bed6ee7a84057a982317996664991a7489ee Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Mon, 29 Mar 2021 14:06:42 +0430 Subject: [PATCH 14/23] Change a word MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changed `می شود` to `شده` for reading purposes. --- 1-js/02-first-steps/13-while-for/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/13-while-for/article.md b/1-js/02-first-steps/13-while-for/article.md index d8d1fdb9d..419c7c40c 100644 --- a/1-js/02-first-steps/13-while-for/article.md +++ b/1-js/02-first-steps/13-while-for/article.md @@ -40,7 +40,7 @@ while (i < 3) { // 0 را نمایش می دهد، سپس 1، سپس 2 ```js run let i = 3; *!* -while (i) { // وقتی که i برابر با 0 شود، شرط falsy می شود، و حلقه متوقف می شود +while (i) { // وقتی که i برابر با 0 شود، شرط falsy شده، و حلقه متوقف می شود */!* alert( i ); i--; From a4dca95ffc9b1c8e06c6394b89a389f2d819c42e Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Mon, 29 Mar 2021 15:51:56 +0430 Subject: [PATCH 15/23] Translate second part of article.md --- 1-js/02-first-steps/13-while-for/article.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/1-js/02-first-steps/13-while-for/article.md b/1-js/02-first-steps/13-while-for/article.md index 419c7c40c..3df6a76da 100644 --- a/1-js/02-first-steps/13-while-for/article.md +++ b/1-js/02-first-steps/13-while-for/article.md @@ -58,19 +58,19 @@ while (i) alert(i--); ``` ```` -## The "do..while" loop +## حلقه "do..while" -The condition check can be moved *below* the loop body using the `do..while` syntax: +بررسی شرط با استفاده از سینتکس `do..while` می تواند به *پایین* بدنه حلقه منتقل شود. ```js do { - // loop body + // بدنه حلقه } while (condition); ``` -The loop will first execute the body, then check the condition, and, while it's truthy, execute it again and again. +حلقه اول بدنه را اجرا می کند، سپس شرط را بررسی می کند، و تا وقتی که truthy باشد، دوباره و دوباره آن(بدنه) را اجرا می کند. -For example: +برای مثال: ```js run let i = 0; @@ -80,7 +80,7 @@ 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(…) {…}`. +این شکل از سینتکس باید فقط زمانی استفاده شود که شما بخواهید بدنه حلقه جدای از اینکه شرط truthy باشد **حداقل یک بار** اجرا شود. معمولا، شکل دیگر ترجیح داده می شود: `while(...) {...}`. ## The "for" loop From fafbb9a274bcb79b0b9968157adb99bcaa73ea16 Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Mon, 29 Mar 2021 21:34:33 +0430 Subject: [PATCH 16/23] Translate third part of article.md --- 1-js/02-first-steps/13-while-for/article.md | 62 ++++++++++----------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/1-js/02-first-steps/13-while-for/article.md b/1-js/02-first-steps/13-while-for/article.md index 3df6a76da..683d58656 100644 --- a/1-js/02-first-steps/13-while-for/article.md +++ b/1-js/02-first-steps/13-while-for/article.md @@ -82,85 +82,85 @@ do { این شکل از سینتکس باید فقط زمانی استفاده شود که شما بخواهید بدنه حلقه جدای از اینکه شرط truthy باشد **حداقل یک بار** اجرا شود. معمولا، شکل دیگر ترجیح داده می شود: `while(...) {...}`. -## The "for" loop +## حلقه "for" -The `for` loop is more complex, but it's also the most commonly used loop. +حلقه `for` پیچیده تر است، اما این حلقه بیشترین استفاده را هم دارد. -It looks like this: +اینطور به نظر می رسد: ```js for (begin; condition; step) { - // ... loop body ... + // ... بدنه حلقه ... } ``` -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`: +بیایید معنی این قسمت ها را با مثال یاد بگیریم. حلقه زیر `alert(i)` را برای هر `i` از `0` تا `3` (اما شامل نمی شود) اجرا می کند: ```js run -for (let i = 0; i < 3; i++) { // shows 0, then 1, then 2 +for (let i = 0; i < 3; i++) { // 0 را نمایش می دهد، سپس 1، سپس 2 alert(i); } ``` -Let's examine the `for` statement part-by-part: +بیایید دستور `for` را قسمت به قسمت بازرسی کنیم: -| part | | | +| قسمت | | | |-------|----------|----------------------------------------------------------------------------| -| 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. | +| begin(آغاز) | `i = 0` | به محض ورود به حلقه اجرا می شود. | +| condition(شرط) | `i < 3`| قبل از هر تکرار حلقه بررسی می شود. اگر false باشد حلقه متوقف می شود. | +| body(بدنه) | `alert(i)`| تا زمانی که شرط truthy باشد همچنان اجرا می شود. | +| step(قدم) | `i++` | در هر تکرار بعد از بدنه اجرا می شود. | -The general loop algorithm works like this: +الگوریتم کلی حلقه مثل قسمت پایین کار می کند: ``` -Run begin -→ (if condition → run body and run step) -→ (if condition → run body and run step) -→ (if condition → run body and run step) +begin را اجرا کن +→ (if condition → body را اجرا کن و step را اجرا کن) +→ (if condition → body را اجرا کن و step را اجرا کن) +→ (if condition → body را اجرا کن و step را اجرا کن) → ... ``` -That is, `begin` executes once, and then it iterates: after each `condition` test, `body` and `step` are executed. +یعنی اینکه، `begin` یک بار اجرا می شود، و سپس این تکرار می شود: بعد از هر بار آزمایش `condition`، `body` و `step` اجرا می شوند. -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. +اگر شما در حلقه ها تازه وارد هستید، این می تواند کمک کند که به مثال برگردید و چگونگی اجرا شدن آن را مرحله به مرحله روی یک کاغذ بنویسید. -Here's exactly what happens in our case: +اینکه در این مورد ما چه اتفاقی می افتد اینجا آورده شده: ```js // for (let i = 0; i < 3; i++) alert(i) -// run begin +// begin را اجرا کن let i = 0 -// if condition → run body and run step +// if condition → body را اجرا کن و step را اجرا کن if (i < 3) { alert(i); i++ } -// if condition → run body and run step +// if condition → body را اجرا کن و step را اجرا کن if (i < 3) { alert(i); i++ } -// if condition → run body and run step +// if condition → body را اجرا کن و step را اجرا کن if (i < 3) { alert(i); i++ } -// ...finish, because now i == 3 +// ...پایان، چون حالا 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="تعریف درون خطی متغیر" +اینجا، متغیر "شمارنده" `i` دقیقا داخل حلقه تعریف شده است. این یک تعریف "درون خطی" متغیر نامیده می شود. این چنین متغیرهایی تنها داخل حلقه قابل دیدن هستند. ```js run for (*!*let*/!* i = 0; i < 3; i++) { alert(i); // 0, 1, 2 } -alert(i); // error, no such variable +alert(i); // ارور، چنین متغیری وجود ندارد ``` -Instead of defining a variable, we could use an existing one: +به جای تعریف کردن یک متغیر، ما می توانستیم از یک متغیر موجود استفاده کنیم: ```js run let i = 0; -for (i = 0; i < 3; i++) { // use an existing variable +for (i = 0; i < 3; i++) { // استفاده از یک متغیر موجود alert(i); // 0, 1, 2 } -alert(i); // 3, visible, because declared outside of the loop +alert(i); // 3، قابل دیدن است، چون بیرون از حلقه تعریف شده است ``` ```` From d091837bc673b6ab99aaee17c21f46983f253853 Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Mon, 29 Mar 2021 23:22:44 +0430 Subject: [PATCH 17/23] Translate forth part of article.md --- 1-js/02-first-steps/13-while-for/article.md | 22 ++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/1-js/02-first-steps/13-while-for/article.md b/1-js/02-first-steps/13-while-for/article.md index 683d58656..0f3ccaf25 100644 --- a/1-js/02-first-steps/13-while-for/article.md +++ b/1-js/02-first-steps/13-while-for/article.md @@ -166,23 +166,23 @@ alert(i); // 3، قابل دیدن است، چون بیرون از حلقه تع ```` -### Skipping parts +### قسمت های قابل جا انداختن -Any part of `for` can be skipped. +هر قسمت `for` را می توان از قلم انداخت. -For example, we can omit `begin` if we don't need to do anything at the loop start. +برای مثال، ما می توانیم `begin` را حذف کنیم اگر نیاز به انجام کاری در آغاز حلقه ندشته باشیم. -Like here: +مثل اینجا: ```js run -let i = 0; // we have i already declared and assigned +let i = 0; // ما i را داریم که از قبل تعریف شده و تخصیص داده شده است. -for (; i < 3; i++) { // no need for "begin" +for (; i < 3; i++) { // نیازی به "begin" نیست alert( i ); // 0, 1, 2 } ``` -We can also remove the `step` part: +همچنین ما می توانیم قسمت `step` را حذف کنیم: ```js run let i = 0; @@ -192,17 +192,17 @@ for (; i < 3;) { } ``` -This makes the loop identical to `while (i < 3)`. +این کار حلقه را شبیه `while (i < 3)` می کند. -We can actually remove everything, creating an infinite loop: +در واقع ما می توانیم همه چیز را حذف کنیم، یک حلقه بی نهایت بسازیم: ```js for (;;) { - // repeats without limits + // بدون محدودیت تکرار می شود } ``` -Please note that the two `for` semicolons `;` must be present. Otherwise, there would be a syntax error. +لطفا در نظر داشته باشید که هر دو نقطه ویرگول `;` داخل `for` باید وجود داشته باشند. در غیر این صورت، یک ارور سینتکس به وجود خواهد آمد. ## Breaking the loop From 0261a80a1adc247987d7646a023e305e94d94efa Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Tue, 30 Mar 2021 12:38:52 +0430 Subject: [PATCH 18/23] Translate 5th part of article.md --- 1-js/02-first-steps/13-while-for/article.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/1-js/02-first-steps/13-while-for/article.md b/1-js/02-first-steps/13-while-for/article.md index 0f3ccaf25..e731c47c5 100644 --- a/1-js/02-first-steps/13-while-for/article.md +++ b/1-js/02-first-steps/13-while-for/article.md @@ -204,20 +204,20 @@ for (;;) { لطفا در نظر داشته باشید که هر دو نقطه ویرگول `;` داخل `for` باید وجود داشته باشند. در غیر این صورت، یک ارور سینتکس به وجود خواهد آمد. -## Breaking the loop +## شکستن حلقه -Normally, a loop exits when its condition becomes falsy. +به طور معمول، یک حلقه زمانی که شرط آن falsy شود متوقف می شود. -But we can force the exit at any time using the special `break` directive. +اما ما می توانیم با استفاده از دستور خاص `break` آن را در هر لحظه مجبور به توقف کنیم. -For example, the loop below asks the user for a series of numbers, "breaking" when no number is entered: +برای مثال، حلقه زیر از کاربر یک سری عدد درخواست می کند، و زمانی که هیچ عددی وارد نشد "می شکند": ```js run let sum = 0; while (true) { - let value = +prompt("Enter a number", ''); + let value = +prompt("یک عدد وارد کنید", ''); *!* if (!value) break; // (*) @@ -226,12 +226,12 @@ while (true) { sum += value; } -alert( 'Sum: ' + sum ); +alert( 'مجموع: ' + 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`. +دستور `break` اگر کاربر یک خط خالی وارد کند یا ورودی را لغو کند در خط `(*)` فعال می شود. حلقه را بلافاصله متوقف می کند، و کنترل را به اولین خط بعد از حلقه می سپارد. یعنی، `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. +ترکیب "حلقه بی نهایت + `break` در صورت نیاز" برای موقعیت هایی که یک شرط حلقه نباید در آغاز یا انتهای حلقه بررسی شود، بلکه در وسط یا حتی چند جای بدنه آن بررسی شود عالی است. ## Continue to the next iteration [#continue] From b0d6e904d436f3ad7acfc5c72d91fb4aae37a806 Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Tue, 30 Mar 2021 16:47:09 +0430 Subject: [PATCH 19/23] Translate 6th part of article.md --- 1-js/02-first-steps/13-while-for/article.md | 36 ++++++++++----------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/1-js/02-first-steps/13-while-for/article.md b/1-js/02-first-steps/13-while-for/article.md index e731c47c5..0c89ca500 100644 --- a/1-js/02-first-steps/13-while-for/article.md +++ b/1-js/02-first-steps/13-while-for/article.md @@ -233,28 +233,28 @@ alert( 'مجموع: ' + sum ); ترکیب "حلقه بی نهایت + `break` در صورت نیاز" برای موقعیت هایی که یک شرط حلقه نباید در آغاز یا انتهای حلقه بررسی شود، بلکه در وسط یا حتی چند جای بدنه آن بررسی شود عالی است. -## Continue to the next iteration [#continue] +## ادامه دادن به تکرار بعدی [#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). +دستور `continue` یک "نسخه سبک تر" از `break` است. حلقه را متوقف نمی کند. در عوض، تکرار حال حاضر را متوقف می کند و حلقه را مجبور می کند که یک تکرار جدید را شروع کند (اگر شرط اجازه دهد). -We can use it if we're done with the current iteration and would like to move on to the next one. +ما می توانیم در صورتی که با تکرار حال حاضر کارمان تمام شده باشد و بخواهیم به تکرار بعدی برویم از آن استفاده کنیم. -The loop below uses `continue` to output only odd values: +حلقه پایین از `continue` فقط برای نشان دادن مقدارهای فرد استفاده می کند. ```js run no-beautify for (let i = 0; i < 10; i++) { - // if true, skip the remaining part of the body + // اگر true باشد، قسمت باقی مانده بدنه را از قلم بنداز *!*if (i % 2 == 0) continue;*/!* - alert(i); // 1, then 3, 5, 7, 9 + alert(i); // 1، سپس 9 ،7 ،5 ،3 } ``` -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. +برای مقدار های زوج `i`، دستور `continue` اجرا کردن بدنه را متوقف می کند و کنترل را به تکرار بعدی `for` می دهد (به همراه عدد بعدی). پس `alert` فقط برای مقدارهای فرد صدا زده می شود. -````smart header="The `continue` directive helps decrease nesting" -A loop that shows odd values could look like this: +````smart header="دستور `continue` به کم کردن تو در تو بودن کمک می کند" +یک حلقه که اعداد فرد را نمایش می دهد می توانست اینطور باشد: ```js run 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`. +از دیدگاه فنی، این شبیه مثال بالا است. مسلما، ما می توانیم کد را داخل یک بلوک `if` بگذاریم به جای اینکه از `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. +اما به عنوان یک عارضه جانبی، یک سطح بیشتری از تو در تویی می سازد (صدا زدن `alert` داخل آکولادها). اگر کد داخل `if` بیشتر از چند خط باشد، ممکن است خوانایی کلی را کاهش دهد. ```` -````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="ممنوعیت `break/continue` در سمت راست '?'" +لطفا در نظر داشته باشید که ساختارهای سینتکس که عبارت نیستند نمی توانند با عملگر ternary `?` استفاده شوند. به خصوص، دستورهایی مثل `break/continue` مجاز نیستند. -For example, if we take this code: +برای مثال، اگر ما این کد را در نظر بگیریم: ```js if (i > 5) { @@ -284,16 +284,16 @@ if (i > 5) { } ``` -...and rewrite it using a question mark: +...و آن را با استفاده از علامت سوال دوباره بنویسیم: ```js no-beautify -(i > 5) ? alert(i) : *!*continue*/!*; // continue isn't allowed here +(i > 5) ? alert(i) : *!*continue*/!*; // continue اینجا مجاز نیست ``` -...it stops working: there's a syntax error. +...متوقف می شود: چون یک ارور سینتکس وجود دارد. -This is just another reason not to use the question mark operator `?` instead of `if`. +این یک دلیل دیگری برای استفاده نکردن از عملگر علامت سوال `?` به جای `if` است. ```` ## Labels for break/continue From ed966a3233a8732bc60256aa8418583514798c09 Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Tue, 30 Mar 2021 19:09:41 +0430 Subject: [PATCH 20/23] Translate article.md The translation was a little tricky so please review and comment / commit if anything is wrong. --- 1-js/02-first-steps/13-while-for/article.md | 68 ++++++++++----------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/1-js/02-first-steps/13-while-for/article.md b/1-js/02-first-steps/13-while-for/article.md index 0c89ca500..6c5894a48 100644 --- a/1-js/02-first-steps/13-while-for/article.md +++ b/1-js/02-first-steps/13-while-for/article.md @@ -296,102 +296,102 @@ if (i > 5) { این یک دلیل دیگری برای استفاده نکردن از عملگر علامت سوال `?` به جای `if` است. ```` -## Labels for break/continue +## برچسب هایی برای break/continue -Sometimes we need to break out from multiple nested loops at once. +بعضی اوقات ما نیاز داریم که از چند حلقه تو در تو به یک باره خارج شویم. -For example, in the code below we loop over `i` and `j`, prompting for the coordinates `(i, j)` from `(0,0)` to `(2,2)`: +برای مثال، در کد پایین ما با `i` و `j` حلقه می زنیم، و برای مختصات های `(i, j)` از `(0,0)` تا `(2,2)` prompt می کنیم: ```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(`مقدار در متخصات (${i},${j})`, ''); - // what if we want to exit from here to Done (below)? + // اگر ما بخواهیم از اینجا به تمام (پایین) خارج شویم چه کار کنیم؟ } } -alert('Done!'); +alert('تمام!'); ``` -We need a way to stop the process if the user cancels the input. +ما به راهی نیاز داریم که فرایند را در صورتی که کاربر ورودی را لغو کند متوقف کنیم. -The ordinary `break` after `input` would only break the inner loop. That's not sufficient -- labels, come to the rescue! +`break` معمولی بعد از `input` فقط حلقه داخلی را می شکند. این کافی نیست -- برچسب ها، به کمک می آیند! -A *label* is an identifier with a colon before a loop: +یک *برچسب* مشخص کننده ای است که قبل از یک حلقه همراه دو نقطه می آید: ```js labelName: for (...) { ... } ``` -The `break ` statement in the loop below breaks out to the label: +دستور `break ` در حلقه پایین به برچسب مورد نظر می رسد: ```js run no-beautify *!*outer:*/!* 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(`مقدار در مختصات (${i},${j})`, ''); - // if an empty string or canceled, then break out of both loops + // اگر یک رشته خالی وارد شود یا لغو شود، سپس از هر دو حلقه خارج شو if (!input) *!*break outer*/!*; // (*) - // do something with the value... + // یک کاری با مقدار انجام بده... } } -alert('Done!'); +alert('تمام!'); ``` -In the code above, `break outer` looks upwards for the label named `outer` and breaks out of that loop. +در کد بالا، `break outer` برای پیدا کردن برچسب `outer` بالا را جست و جو می کند و از آن حلقه خارج می شود. -So the control goes straight from `(*)` to `alert('Done!')`. +پس کنترل به صورت مسقیم از `(*)` به `alert('تمام!')` می رسد. -We can also move the label onto a separate line: +همچنین ما می توانیم برچسب را به یک خط جداگانه منتقل کنیم: ```js no-beautify outer: 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. +دستور `continue` هم می تواند به همراه برچسب استفاده شود. در این مورد، اجرای کد به تکرار بعدی از حلقه برچسب زده شده می رود. -````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="برچسب ها اجازه \"پرش\" به جایی را نمی دهند" +برچسب ها به ما اجازه نمی دهند که به جای دلخواهی از کد بپریم. -For example, it is impossible to do this: +برای مثال، این غیر ممکن است که این کار را انجام دهیم: ```js -break label; // jump to the label below (doesn't work) +break label; // پرش به برچسب پایین (کار نمی کند) label: for (...) ``` -A `break` directive must be inside a code block. Technically, any labelled code block will do, e.g.: +یک دستور `break` باید در داخل بلوک کد باشد. از نظر فنی، می تواند هر بلوک برچسب زده شده کد باشد ```js label: { // ... - break label; // works + break label; // کار می کند // ... } ``` -...Although, 99.9% of the time `break` used is inside loops, as we've seen in the examples above. +...اگرچه، %99.9 مواقع `break` در داخل حلقه ها استفاده می شود، همانطور که در مثال های بالا دیدیم. -A `continue` is only possible from inside a loop. +یک `continue` فقط در داخل حلقه می تواند باشد. ```` -## Summary +## خلاصه -We covered 3 types of loops: +ما سه نوع حلقه را پوشش دادیم: -- `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` -- شرط قبل از هر تکرار بررسی می شود. +- `do..while` -- شرط بعد از هر تکرار بررسی می شود. +- `for (;;)` -- شرط قبل از هر تکرار بررسی می شود، تنظیمات بیشتر هم ممکن است. -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. +برای ساخت یک حلقه "بی نهایت"، معمولا ساختار `while(true)` استفاده می شود. چنین حلقه ای، درست مثل هر حلقه، می تواند با دستور `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. +اگر ما نخواهیم که در تکرار حال حاضر کاری کنیم و دوست داشته باشیم که به تکرار بعدی برویم، می توانیم از دستور `continue` استفاده کنیم. -`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` از برچسب های قبل از حلقه پشتیبانی می کنند. یک برچسب تنها راه `break/continue` برای فرار از یک حلقه تو در تو و رفتن به حلقه بیرونی است. From bef576042470c7de4d8f7fe45212a2dea90f1176 Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Tue, 30 Mar 2021 19:11:16 +0430 Subject: [PATCH 21/23] Change a word MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changed "میشود" to "می شود" --- 1-js/02-first-steps/13-while-for/1-loop-last-value/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/13-while-for/1-loop-last-value/task.md b/1-js/02-first-steps/13-while-for/1-loop-last-value/task.md index 22aa800ce..f56845e68 100644 --- a/1-js/02-first-steps/13-while-for/1-loop-last-value/task.md +++ b/1-js/02-first-steps/13-while-for/1-loop-last-value/task.md @@ -4,7 +4,7 @@ importance: 3 # آخرین مقدار حلقه -آخرین مقداری که نمایش داده میشود چیست؟ چرا؟ +آخرین مقداری که نمایش داده می شود چیست؟ چرا؟ ```js let i = 3; From 70c8c9e180682ab05270ac8b1784e5ea4fb5a8f4 Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Tue, 30 Mar 2021 19:29:22 +0430 Subject: [PATCH 22/23] Change two words MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changed "میشود" to "می شود" --- 1-js/02-first-steps/13-while-for/1-loop-last-value/solution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/13-while-for/1-loop-last-value/solution.md b/1-js/02-first-steps/13-while-for/1-loop-last-value/solution.md index 2963fc774..bf9b11841 100644 --- a/1-js/02-first-steps/13-while-for/1-loop-last-value/solution.md +++ b/1-js/02-first-steps/13-while-for/1-loop-last-value/solution.md @@ -8,7 +8,7 @@ while (i) { } ``` -در هر بار تکرار حلقه متغیر `i` به مقدار `1` عدد کم میشود. عبارت `while(i)` وقتی به `i = 0` برسد متوقف میشود. +در هر بار تکرار حلقه متغیر `i` به مقدار `1` عدد کم می شود. عبارت `while(i)` وقتی به `i = 0` برسد متوقف می شود. حالا گام های حلقه به این صورت است ("تشریح حلقه"): From d421e8e3f87514a77ff291a0311920c4065bfb3d Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Tue, 30 Mar 2021 22:03:37 +0430 Subject: [PATCH 23/23] Fix mentioned problems and change some lines All the mentioned problems are fixed and I also changed some lines to make it more readable --- 1-js/02-first-steps/13-while-for/article.md | 42 ++++++++++----------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/1-js/02-first-steps/13-while-for/article.md b/1-js/02-first-steps/13-while-for/article.md index 6c5894a48..454002c7f 100644 --- a/1-js/02-first-steps/13-while-for/article.md +++ b/1-js/02-first-steps/13-while-for/article.md @@ -2,7 +2,7 @@ ما معمولا نیاز داریم که کارها رو تکرار کنیم. -برای مثال، از یک لیست کالاها را یکی پس از دیگری نمایش دهیم یا کد مشابهی رو برای هر عدد از 1 تا 10 اجرا کنیم. +برای مثال، کالاهایی را از یک لیست یکی پس از دیگری نمایش دهیم یا کد مشابهی رو برای هر عدد از 1 تا 10 اجرا کنیم. *حلقه ها* راهی برای تکرار یک کد برای چندین بار هستند. @@ -17,9 +17,9 @@ while (condition) { } ``` -تا وقتی که `condition` برابر با truthy باشد، `کد` قسمت بدنه حلقه اجرا می شود. +تا وقتی که `condition` truthy باشد، `کد` قسمت بدنه حلقه اجرا می شود. -برای مثال، حلقه پایین `i` را نمایش می دهد تا وقتی که `i < 3`: +برای مثال، حلقه پایین `i` را تا وقتی که `i < 3` باشد، نمایش می دهد: ```js run let i = 0; @@ -29,7 +29,7 @@ while (i < 3) { // 0 را نمایش می دهد، سپس 1، سپس 2 } ``` -یک بار اجرا شدن بدنه حلقه *یک تکرار* نامیده می شود. حلقه داخل مثال بالا سه تکرار می سازد. +یک بار اجرا شدن بدنه حلقه را *یک تکرار* می نامند. حلقه داخل مثال بالا سه تکرار می سازد. اگر `i++` از مثال بالا جا می ماند، حلقه (در تئوری) برای همیشه اجرا می شد. در عمل، مرورگر راه هایی را برای متوقف کردن چنین حلقه هایی مهیا می کند، و در جاوااسکریپت سمت سرور، ما می توانیم فرایند را نابود کنیم. @@ -94,7 +94,7 @@ for (begin; condition; step) { } ``` -بیایید معنی این قسمت ها را با مثال یاد بگیریم. حلقه زیر `alert(i)` را برای هر `i` از `0` تا `3` (اما شامل نمی شود) اجرا می کند: +بیایید معنی این قسمت ها را با مثال یاد بگیریم. حلقه زیر `alert(i)` را برای هر `i` از `0` تا `3` (خود 3 شامل نمی شود) اجرا می کند: ```js run for (let i = 0; i < 3; i++) { // 0 را نمایش می دهد، سپس 1، سپس 2 @@ -102,7 +102,7 @@ for (let i = 0; i < 3; i++) { // 0 را نمایش می دهد، سپس 1، سپ } ``` -بیایید دستور `for` را قسمت به قسمت بازرسی کنیم: +بیایید شرح `for` را قسمت به قسمت بررسی کنیم: | قسمت | | | |-------|----------|----------------------------------------------------------------------------| @@ -123,9 +123,9 @@ begin را اجرا کن یعنی اینکه، `begin` یک بار اجرا می شود، و سپس این تکرار می شود: بعد از هر بار آزمایش `condition`، `body` و `step` اجرا می شوند. -اگر شما در حلقه ها تازه وارد هستید، این می تواند کمک کند که به مثال برگردید و چگونگی اجرا شدن آن را مرحله به مرحله روی یک کاغذ بنویسید. +اگر شما تازه با حلقه ها آشنا شدید، به مثال برگردید و مراحل اجرای آن را مرحله به مرحله روی یک کاغذ بازتولید کنید. -اینکه در این مورد ما چه اتفاقی می افتد اینجا آورده شده: +در مورد ما، دقیقا این اتفاق می افتد: ```js // for (let i = 0; i < 3; i++) alert(i) @@ -142,7 +142,7 @@ if (i < 3) { alert(i); i++ } ``` ````smart header="تعریف درون خطی متغیر" -اینجا، متغیر "شمارنده" `i` دقیقا داخل حلقه تعریف شده است. این یک تعریف "درون خطی" متغیر نامیده می شود. این چنین متغیرهایی تنها داخل حلقه قابل دیدن هستند. +اینجا، متغیر "شمارنده" `i` دقیقا داخل حلقه تعریف شده است. این یک تعریف "درون خطی" متغیر نامیده می شود. این چنین متغیرهایی تنها داخل حلقه قابل رویت هستند. ```js run for (*!*let*/!* i = 0; i < 3; i++) { @@ -151,7 +151,7 @@ for (*!*let*/!* i = 0; i < 3; i++) { alert(i); // ارور، چنین متغیری وجود ندارد ``` -به جای تعریف کردن یک متغیر، ما می توانستیم از یک متغیر موجود استفاده کنیم: +ما می توانستیم به جای تعریف کردن یک متغیر، از یک متغیر موجود استفاده کنیم: ```js run let i = 0; @@ -170,7 +170,7 @@ alert(i); // 3، قابل دیدن است، چون بیرون از حلقه تع هر قسمت `for` را می توان از قلم انداخت. -برای مثال، ما می توانیم `begin` را حذف کنیم اگر نیاز به انجام کاری در آغاز حلقه ندشته باشیم. +برای مثال، اگر نیاز به انجام کاری در آغاز حلقه نداشته باشیم می توانیم `begin` را حذف کنیم. مثل اینجا: @@ -192,7 +192,7 @@ for (; i < 3;) { } ``` -این کار حلقه را شبیه `while (i < 3)` می کند. +این کار حلقه را برابر با `while (i < 3)` می کند. در واقع ما می توانیم همه چیز را حذف کنیم، یک حلقه بی نهایت بسازیم: @@ -202,15 +202,15 @@ for (;;) { } ``` -لطفا در نظر داشته باشید که هر دو نقطه ویرگول `;` داخل `for` باید وجود داشته باشند. در غیر این صورت، یک ارور سینتکس به وجود خواهد آمد. +لطفا در نظر داشته باشید که هر دو نقطه ویرگول `;` داخل `for` باید وجود داشته باشند. در غیر این صورت، یک سینتکس ارور به وجود خواهد آمد. -## شکستن حلقه +## متوقف کردن حلقه به طور معمول، یک حلقه زمانی که شرط آن falsy شود متوقف می شود. اما ما می توانیم با استفاده از دستور خاص `break` آن را در هر لحظه مجبور به توقف کنیم. -برای مثال، حلقه زیر از کاربر یک سری عدد درخواست می کند، و زمانی که هیچ عددی وارد نشد "می شکند": +برای مثال، حلقه زیر از کاربر یک سری عدد درخواست می کند، و زمانی که هیچ عددی وارد نشد "متوقف می شود": ```js run let sum = 0; @@ -229,7 +229,7 @@ while (true) { alert( 'مجموع: ' + sum ); ``` -دستور `break` اگر کاربر یک خط خالی وارد کند یا ورودی را لغو کند در خط `(*)` فعال می شود. حلقه را بلافاصله متوقف می کند، و کنترل را به اولین خط بعد از حلقه می سپارد. یعنی، `alert`. +اگر کاربر یک خط خالی وارد کند یا ورودی را لغو کند دستور `break` در خط `(*)` فعال می شود. حلقه را بلافاصله متوقف می کند، و کنترل را به اولین خط بعد از حلقه می سپارد. یعنی، `alert`. ترکیب "حلقه بی نهایت + `break` در صورت نیاز" برای موقعیت هایی که یک شرط حلقه نباید در آغاز یا انتهای حلقه بررسی شود، بلکه در وسط یا حتی چند جای بدنه آن بررسی شود عالی است. @@ -291,7 +291,7 @@ if (i > 5) { (i > 5) ? alert(i) : *!*continue*/!*; // continue اینجا مجاز نیست ``` -...متوقف می شود: چون یک ارور سینتکس وجود دارد. +...متوقف می شود: چون یک سینتکس ارور وجود دارد. این یک دلیل دیگری برای استفاده نکردن از عملگر علامت سوال `?` به جای `if` است. ```` @@ -318,7 +318,7 @@ alert('تمام!'); ما به راهی نیاز داریم که فرایند را در صورتی که کاربر ورودی را لغو کند متوقف کنیم. -`break` معمولی بعد از `input` فقط حلقه داخلی را می شکند. این کافی نیست -- برچسب ها، به کمک می آیند! +`break` معمولی بعد از `input` فقط حلقه داخلی را متوقف می کند. این کافی نیست -- برچسب ها، به کمک می آیند! یک *برچسب* مشخص کننده ای است که قبل از یک حلقه همراه دو نقطه می آید: ```js @@ -361,14 +361,14 @@ for (let i = 0; i < 3; i++) { ... } ````warn header="برچسب ها اجازه \"پرش\" به جایی را نمی دهند" برچسب ها به ما اجازه نمی دهند که به جای دلخواهی از کد بپریم. -برای مثال، این غیر ممکن است که این کار را انجام دهیم: +برای مثال، انجام دادن این کار غیر ممکن است: ```js break label; // پرش به برچسب پایین (کار نمی کند) label: for (...) ``` -یک دستور `break` باید در داخل بلوک کد باشد. از نظر فنی، می تواند هر بلوک برچسب زده شده کد باشد +یک دستور `break` باید در داخل بلوک کد باشد. از نظر فنی، آن بلوک می تواند هر بلوک کد برچسب زده باشد ```js label: { // ... @@ -379,7 +379,7 @@ label: { ...اگرچه، %99.9 مواقع `break` در داخل حلقه ها استفاده می شود، همانطور که در مثال های بالا دیدیم. -یک `continue` فقط در داخل حلقه می تواند باشد. +یک `continue` فقط می تواند در داخل حلقه باشد. ```` ## خلاصه