JavaScript for loop
Notes:
for loop: Entry control loop:
Browser executes the statement(s) inside the for loop, until the given conditional expression evaluates to false.
Syntax:
for(initialization; conditional expression; increment/decrement)
{
statement(s);
}
Ex:
for( var i=1; i<=5; i++ )
{
document.write(“Hello World <br/>”);
}
Note: When you know exactly how many # of times the loop is going to get execute, use for loop.
Interview Questions:
1. When to use for loop ?
a. when we know exactly how many # of times the loop gets executed
b. when we don't know exactly how many times the loop gets executed
c. To execute a statement or set of statements at least once
d. When we need to loop through the properties of an object
Answer: a