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

Example 6.17:
Duplicating a do while Loop


The button calls function1(), which duplicates a 'do while' loop. Even though variable sWord is already set to Aardvark, the Prompt dialog box will open. If you don't type anything, or if you type something other than Aardvark, the while loop kicks in:


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