Return to Kroll Web Design home page

JavaScript Tutorials

« Return

for loop

The "for" statement is a popular method for doing iterative loops.

Make sure that you don't put a semicolon after the right paren:

Wrong: for (i=0; i<10; i++); { /* code goes here */ }
Right: for (i=0; i<10; i++) { /* code goes here */ }

Code:

<script type="text/javascript">
//<![CDATA[
i = 1; for (i=1; i<=10; i++) { document.write(i, "<br>"); } //]]> </script>

Output:




©2010 Kroll Web Design    davidarthurkroll@verizon.net    781.910.3694