JavaScript For Loop and It's Example

for loop

The for loop is the most compact form of looping and includes the following three important parts:

The loop initialization where we initialize our counter to a starting value. The initialization statement is executed before the loop begins.

The test statement which will test if the given condition is true or not. If condition is true then code given inside the loop will be execured otherwise loop will come out.

The iteration statement where counter value is incremented or decremented.


for(initialization; test condition; iteration statement)
  Statements(s) to be executed if test condition is true

Flow Chart:

Example :


Counter = 0
Counter = 1
Counter = 2
Counter = 3

Read also: