Java Script


JavaScript Tutorial


Admission Enquiry Form


What is For loop in JavaScript?

For loop is a known loop in JavaScript.In for loop we know about the number of repetitions in the code.

Syntax For loop

for(initialization;condition;increment/decrement)
    {
    // statements.
    }

Example of For loop:

<html>
<head>
<title>for loop</title>
</head>
<body>
<script>
var i;
for(i=1;i<=5;i++)
{
document.write("Compuhelp<br>");
}
</script>
</body>
</html>

Output:

Compuhelp
Compuhelp
Compuhelp
Compuhelp
Compuhelp

In the above example, the for loop will print Compuhelp 5 times.