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

Example 6.16:
A 'while' Loop Without a Counter


The button calls function1(), which uses a 'while' loop. This displays the Prompt dialog box until the user types the word Aardvark (make sure you type the A uppercase):


This is the script we used: <SCRIPT LANGUAGE="JavaScript"> <!-- function function1() { var sWord ="" while (sWord != "Aardvark") { sWord = prompt("Input the word \'Aardvark\' in order to stop the loop","") } alert("The loop has finished") } //--> </SCRIPT> </HEAD> <BODY> <BR> <form> <input type="button" value=" Button A " onclick="function1()"> </form>
Previous Example-|-Next Example-|-Return to Chapter Listing