Online

JavaScript - For Loop

The 'for' loop is the most compact form of looping. It 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 a given condition is true or not. If the condition is true, then the code given inside the loop will be executed, otherwise the control will come out of the loop.
  • The iteration statement where you can increase or decrease your counter.
  • Syntax :-

    Example :-

    Result

    Starting Loop

    Current Count : 0

    Current Count : 1

    Current Count : 2

    Current Count : 3

    Current Count : 4

    Current Count : 5

    Current Count : 6

    Current Count : 7

    Current Count : 8

    Current Count : 9

    Loop stopped!