Looping in JavaScript is a feature which executes a set of instructions repeatedly. In an example we went over in previous classes, if we wanted to say “hello world” ten times. This set of instructions could be done in two different ways. One method is to write the command “hello world” ten separate times. A much more efficient to get this result is to use a for loop.
An example of what a for loop would look like in JavaScript is shown below:
vari;
for (i = 0; i < 10; i++)
{
document.write(“hello world”);
}
The first i shows that the program will begin at zero. The second i shows that the program will not generate “hello world” more than ten times. The third i shows that i will increase in increments of one.
Leave a Reply
You must be logged in to post a comment.