2b - Javascript:Control Statements II - For statements
The for statement will execute a block of code a specified number of times.
for (initialization; condition; increment)
{
code to be executed
}
Let's experiment
Now let's open Notepad and try our own.
<html>
<head>
<title>
For statement test
</title>
</head>
<body>
<script type="text/javascript">
<!--
//Initialization,repetition condition and incrementing are
all included
// in the for statement header
for (var counter = 1; counter <= 7; ++counter){
document.writeln("<p
style = \"font-size: " + counter + "ex\">XHTML font size
" + counter " + "ex</p>");
}
//-->
</script>
</body>
</html>