|
| FOR LOOPS IN JAVASCRIPT
A for loop in javascript executes a block of code between the curly braces a specified number of times. The condition is evaluated first before the block of code between the curly braces can execute.
The general format is:
for(starting mark; condition; increment)
{
execute this code;
}
Example:
for(i=1; i < 6 ; i++)
{
document.write("Bart Simpson was here.<br>");
}
Our starting mark will assign our variable i to 1 ie. we want to start with i=1. We want to stop when i is less than 6 ie. i must be no more than 5. The above code will output Bart Simpson was here. five times and only stop executing when i is equal to 6.
|
|