for

Iterates through the loop, starting from the specified initial condition and will iterate through the statements enclosed within the { code block } until the test is false. The initial condition, test and iterator are separated with a semi-colon ;

 

Syntax:

for (initialisertestiterator ) {

statements ;

}

 

 

<html>
	<head>
		<title>JavaScript</title>
	</head>
	<body>
	<script type="text/javascript">
		var val ;

		for (val = 10; val < 15; val++) {
			document.write("val = " + val + "<br>");

		}
	</script>
	</body>
</html>

Save & refresh browser:

val = 10
val = 11
val = 12
val = 13
val = 14

Leave a Reply