JavaScript Comparing For and While Loop
Both the loops are similar in some ways, like both are used for repeated execution of statements as well as execution are done till the condition is true.
For loop and while loop they differ by the syntax as,
For loop Syntax :
for(initialization; Condition ; variable updater) {
statement 1;
.
.
.
statement n;
}
Here the first variable gets initialized then the condition for the loop is checked and then the variable is updated as incremented or decremented.
The iterations of statements are done till the condition gets false.
While loop Syntax: while (Condition)
{
statements; // statements to be executed
}
In while loop first the condition is checked if only it gets true then only the statements get executed, the iteration of statements execution are done till the condition gets false
0 Comment(s)