JavaScript For Loop - Java Script

What is JavaScript -For Loop?

As we all know, Looping is often used when one needs to execute a block of code again until a particular condition is satisfied. It includes mainly three important components − initialization, test condition and iteration(increment/decrement). You can keep all the components in a single line separated by semicolons.

  • Initialization: This is where a variable gets initialized and assigned to a starting value i.e the counter is initialized to starting value. The initialization statement is executed before the loop begins.

  • Test condition: This is where the condition check happens. Here a variable is tested for a given condition. While executing, it checks whether the condition is true , else it comes out of the loop and start executing the next set of code.

  • Iteration: This is where increment or decrement of variablehappens.

Flow Chart of For Loop:

Below is the flow chart of For loop in JavaScript −

Flow Chart of For Loop

Syntax:
Below is the syntax for 'For' loop.
Example:
Look at thebelow example to understand the implementation of 'for' loopJavaScript.
This will produce the below output:
Flow Chart of For Loop

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Java Script Topics