1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/js1_2/statements/break.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,130 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 + 1.10 +/** 1.11 + Filename: break.js 1.12 + Description: 'Tests the break statement' 1.13 + 1.14 + Author: Nick Lerissa 1.15 + Date: March 18, 1998 1.16 +*/ 1.17 + 1.18 +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; 1.19 +var VERSION = 'no version'; 1.20 +startTest(); 1.21 +var TITLE = 'statements: break'; 1.22 + 1.23 +writeHeaderToLog("Executing script: break.js"); 1.24 +writeHeaderToLog( SECTION + " "+ TITLE); 1.25 + 1.26 +var i,j; 1.27 + 1.28 +for (i = 0; i < 1000; i++) 1.29 +{ 1.30 + if (i == 100) break; 1.31 +} 1.32 + 1.33 +// 'breaking out of "for" loop' 1.34 +new TestCase ( SECTION, 'breaking out of "for" loop', 1.35 + 100, i); 1.36 + 1.37 +j = 2000; 1.38 + 1.39 +out1: 1.40 +for (i = 0; i < 1000; i++) 1.41 +{ 1.42 + if (i == 100) 1.43 + { 1.44 + out2: 1.45 + for (j = 0; j < 1000; j++) 1.46 + { 1.47 + if (j == 500) break out1; 1.48 + } 1.49 + j = 2001; 1.50 + } 1.51 + j = 2002; 1.52 +} 1.53 + 1.54 +// 'breaking out of a "for" loop with a "label"' 1.55 +new TestCase ( SECTION, 'breaking out of a "for" loop with a "label"', 1.56 + 500, j); 1.57 + 1.58 +i = 0; 1.59 + 1.60 +while (i < 1000) 1.61 +{ 1.62 + if (i == 100) break; 1.63 + i++; 1.64 +} 1.65 + 1.66 +// 'breaking out of a "while" loop' 1.67 +new TestCase ( SECTION, 'breaking out of a "while" loop', 1.68 + 100, i ); 1.69 + 1.70 + 1.71 +j = 2000; 1.72 +i = 0; 1.73 + 1.74 +out3: 1.75 +while (i < 1000) 1.76 +{ 1.77 + if (i == 100) 1.78 + { 1.79 + j = 0; 1.80 + out4: 1.81 + while (j < 1000) 1.82 + { 1.83 + if (j == 500) break out3; 1.84 + j++; 1.85 + } 1.86 + j = 2001; 1.87 + } 1.88 + j = 2002; 1.89 + i++; 1.90 +} 1.91 + 1.92 +// 'breaking out of a "while" loop with a "label"' 1.93 +new TestCase ( SECTION, 'breaking out of a "while" loop with a "label"', 1.94 + 500, j); 1.95 + 1.96 +i = 0; 1.97 + 1.98 +do 1.99 +{ 1.100 + if (i == 100) break; 1.101 + i++; 1.102 +} while (i < 1000); 1.103 + 1.104 +// 'breaking out of a "do" loop' 1.105 +new TestCase ( SECTION, 'breaking out of a "do" loop', 1.106 + 100, i ); 1.107 + 1.108 +j = 2000; 1.109 +i = 0; 1.110 + 1.111 +out5: 1.112 +do 1.113 +{ 1.114 + if (i == 100) 1.115 + { 1.116 + j = 0; 1.117 + out6: 1.118 + do 1.119 + { 1.120 + if (j == 500) break out5; 1.121 + j++; 1.122 + }while (j < 1000); 1.123 + j = 2001; 1.124 + } 1.125 + j = 2002; 1.126 + i++; 1.127 +}while (i < 1000); 1.128 + 1.129 +// 'breaking out of a "do" loop with a "label"' 1.130 +new TestCase ( SECTION, 'breaking out of a "do" loop with a "label"', 1.131 + 500, j); 1.132 + 1.133 +test();