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

Example 6.20:
Using a Labeled break

[This example works with Netscape Navigator 4. It will not work with Netscape Navigator 3 or Internet Explorer 3.]

This is similar to the previous example, but the function used here has two different breaks, each using a label to define which part of the statement is being broken out from.



This is the function in the HEAD: <SCRIPT LANGUAGE="JavaScript"> <!-- function function1() { var bResult var bResult2 external : for (i = 1; i < 4; i++) { bResult = confirm("i = " + i + "\nClick cancel to execute a \'break\' statement","") if (bResult == false) { bResult2 = confirm("Are you sure? Click OK to break completely out of the loop. Press Cancel to break just the internal part of the loop.") internal : if (bResult2 == true) { break external; } else { break internal; } alert("You broke internal") } } alert("You broke external") } //--> </SCRIPT> This is the button: <form> <input type="button" value=" Pick your break " onclick="function1()"> <P> </form>
Previous Example-|-Next Example-|-Return to Chapter Listing