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

Example 6.15:
A 'while' Loop


The button calls function1(), which uses a 'while' loop. This does the same as Example 6.13 (for) and Example 6.14 (nested if) except that it uses a while loop to do it:


This is the script we used: <SCRIPT LANGUAGE="JavaScript"> <!-- function function1() { var i = 1 while (i < 4) { alert("The value in i is " + i ) 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