whadiz.com: What is?
Search Articles:     Home | About | Tools | Contact Us
Games
Board Games
Online Games
Databases
Sql Server
Programming
Visual C# in ASP.Net
JavaScript
Humor
Satire
Web Design
Html

Clever Facts Section

What is JavaScript for loop? | JavaScript for loop | JavaScript for | Execute JavaScript code predetermined number of times

What is JavaScript for loop?

A JavaScript for loop is used when you know how many times a piece of code should execute. In a JavaScript for loop you normally know the number of iterations in advance. 

What is the syntax for JavaScript for loop?

The syntax for the JavaScript for loop is the following:
for(initialization;condition for looping;update of starting value) {
    //The code that should be repeated
}

What is an example of a JavaScript for loop?

In the following example the JavaScript for loop will execute the code 5 times. The starting value for the variable i in the JavaScript for loop is 0. With each iteration of the JavaScript for loop, the variable i is incremented by 1. The JavaScript for loop will stop as soon as the variable i reaches the value 5.

Example:
var i = 0;
for (i = 0; i < 5; i++) {
    document.write("JavaScript for Loop: " + i + "<br />");
}

The resulting output for this JavaScript for loop is:
JavaScript for Loop: 0
JavaScript for Loop: 1
JavaScript for Loop: 2
JavaScript for Loop: 3
JavaScript for Loop: 4

Link to this article:

Browse some more: Next Article | Next Fact | More JavaScript Articles | More Clever Facts


Copyright © 2023 whadiz.com. All rights reserved.
whadiz.com: What is JavaScript for loop? | JavaScript for loop | JavaScript for | Execute JavaScript code predetermined number of times
Home of the answer "what is"