JavaScript for Loop

« Previous Tutorial Next Tutorial »

The for loop in JavaScript is used to execute a block of code or group of statements multiple times based on the given/particular condition.

Here is the general form to use for loop in JavaScript:

for(initialization; condition-checker; incrementation)
	// block of code, to be executed here

Here is the explanation:

JavaScript for Loop Example

Here is an example illustrates how to use for loop in JavaScript:

	<title>JavaScript for Loop</title>

<h3>JavaScript for Loop Example</h3>
<script type="text/javascript">
	var num = 2;
	document.write("Printing the table of " + num + "<br/>");
	var i;
	for(i=1; i<=10; i++)
		document.write(num*i + "<br/>");


Here is the sample output of the above for loop example in JavaScript:

javascript for loop

« Previous Tutorial Next Tutorial »

Latest 5 Posts by CodesCracker


Quick Links
Signup - Login - Give Online Test