Previous Example-|-Next Example-|-Return to Chapter Listing

Example 6.13:
A 'for' Loop


The button calls function1(), which uses a 'for' loop. Each time around the loop it displays an alert box with the value of the variable 'i'. Also there is an additional alert box after the loop has finished:


This is the script we used: <SCRIPT LANGUAGE="JavaScript"> <!-- function function1() { var i for (i = 0; i < 4; i++) { alert("The value in i is " + i ) } alert("The loop has finished and i is " + i ) } //--> </SCRIPT> </HEAD> <BODY> <BR> <form> <input type="button" value=" Button A " onclick="function1()"> </form>
Previous Example-|-Next Example-|-Return to Chapter Listing