codemarch
codemarch

@codemarch

23 تغريدة 11 قراءة Apr 23, 2022
Master JavaScript.
- Topic 7
Looping Explained: 🧵
- Loops can execute a code a number of times.
Different Kinds of Loops
- For
- loops through a block of code a number of times.
- Executes the loop block for a specified number of times under a termination condition.
Syntax -
Flowchart-
Example 1 -
Example 2 -
- For in loop
- loops through the properties of an object.
Syntax --
Example ---
- For of
loops through the values of an iterable object.
Syntax➖
Example ----
- while loop
- loops through a block of code while a specified condition is true.
Syntax➖
1. A `while` loop evaluates the condition inside the parenthesis ().
2. If the condition evaluates to `true`, the code inside the `while` loop is executed.
3. The condition is evaluated again.
4. This process continues until the condition is `false`.
5. When the condition evaluates to `false`, the loop stops.
Flowchart---
Example 1: Display Numbers from 1 to 5 (While Loop)
- Do-while loop:
- loops through a block of code while a specified condition is true.
Syntax➖
1. The body of the loop is executed at first. Then the condition is evaluated.
2. If the condition evaluates to `true`, the body of the loop inside the `do` statement is executed again.
3. The condition is evaluated once again.
4. If the condition evaluates to `true`, the body of the loop inside the `do` statement is executed again.
5. This process continues until the condition evaluates to `false`. Then the loop stops.
Flowchart -----
Example -----
If you found this thread useful,
1. Do Retweet the first tweet.
2. Follow @CodeMarch
for the amazing content on Javascript & React.

جاري تحميل الاقتراحات...