JavaScript includes for loop like Java or C#. Use for loop to execute code repeatedly.
The for loop requires following three parts.
Initializer: Initialize a counter variable to start with
Condition: specify a condition that must evaluate to true for next iteration
Iteration: increase or decrease counter
Example
- for(int i = 0; i<= 5; i++)
Three parts are separated via ; (semi-colon).
PART 1 :- int i = 0 This part of the for loop is known as initialization. Here we initialize the loop variable which will iterate through the loop.
PART 2 :- i <=5 This part is known as condition or you can say comparison, as it suits but condition is the word which suits here better. This part will set certain condition for loop variable regarding how much time it should iterate.
PART 3 :- i++ This is increment / decrement part. Here the value of loop variable is either incremented or decremented. The value change is done after execution of certain statements in loop. The value keeps changing until the condition is fulfilled.
https://www.tutorialsteacher.com/javascript/javascript-for-loop
Leave a Reply
You must be logged in to post a comment.