Skip to content

Latest commit

 

History

History
63 lines (41 loc) · 1.59 KB

File metadata and controls

63 lines (41 loc) · 1.59 KB

🔓 Loops

Loops are used to repeat the action stated in the curly braces { }.

There are mainly two types of loop that we will be learning:

While Loop

While loop

Have the following syntax

while (condition) {
  // code block to be executed
}

Here's an example:

let counter = 0;
while (counter < 5) {
  console.log("Hi");
  counter++;
}
For Loop

For loop

Have the following syntax

for (statement 1; statement 2; statement 3) {
// code block to be executed
}

Statement 1 is executed (one time) before the execution of the code block.

Statement 2 defines the condition for executing the code block.

Statement 3 is executed (every time) after the code block has been executed.

So here's an example:

for (let counter = 0; counter <= 5; counter++) {
  console.log("HI");
}





◀️ Previous Page : Control Flow : Comparison Operators 🚩 🔓                              🏡                              ▶️ Next Page : Loops : While Loop 🔑