HTML CSS JavaScript SEO Python Posts Privacy About Contact

JS Loop For

Loops can execute a block of code a number of times.

Loops can execute a block of code a number of times. Loops are handy if you want to run the same code over and over again, each time with a different value.

The For Loop

The for loop has 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.
Preview

Looping Over an Array

Often, a for loop is used to iterate over the items inside an array.

Preview

The For…In Loop

The JavaScript for...in statement loops through the properties of an Object.

Preview