ScanSkill

for

The for statement creates a loop.

Syntax

for (initialization; condition; [increment / decrement]) {
  // Statements
}

Example

for(let i = 1; i <= 5; i++) {
  console.log(i);
}
/* Prints:
1
2
3
4
5
*/

The for loop consists of three things, initialization, the second condition, and the final one being increment or decrement of the initialized value of initialization. It combines all the things into the loop body itself unlike the do…while and while loop.