|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 |
|
7 /** |
|
8 Filename: break.js |
|
9 Description: 'Tests the break statement' |
|
10 |
|
11 Author: Nick Lerissa |
|
12 Date: March 18, 1998 |
|
13 */ |
|
14 |
|
15 var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; |
|
16 var VERSION = 'no version'; |
|
17 startTest(); |
|
18 var TITLE = 'statements: break'; |
|
19 |
|
20 writeHeaderToLog("Executing script: break.js"); |
|
21 writeHeaderToLog( SECTION + " "+ TITLE); |
|
22 |
|
23 var i,j; |
|
24 |
|
25 for (i = 0; i < 1000; i++) |
|
26 { |
|
27 if (i == 100) break; |
|
28 } |
|
29 |
|
30 // 'breaking out of "for" loop' |
|
31 new TestCase ( SECTION, 'breaking out of "for" loop', |
|
32 100, i); |
|
33 |
|
34 j = 2000; |
|
35 |
|
36 out1: |
|
37 for (i = 0; i < 1000; i++) |
|
38 { |
|
39 if (i == 100) |
|
40 { |
|
41 out2: |
|
42 for (j = 0; j < 1000; j++) |
|
43 { |
|
44 if (j == 500) break out1; |
|
45 } |
|
46 j = 2001; |
|
47 } |
|
48 j = 2002; |
|
49 } |
|
50 |
|
51 // 'breaking out of a "for" loop with a "label"' |
|
52 new TestCase ( SECTION, 'breaking out of a "for" loop with a "label"', |
|
53 500, j); |
|
54 |
|
55 i = 0; |
|
56 |
|
57 while (i < 1000) |
|
58 { |
|
59 if (i == 100) break; |
|
60 i++; |
|
61 } |
|
62 |
|
63 // 'breaking out of a "while" loop' |
|
64 new TestCase ( SECTION, 'breaking out of a "while" loop', |
|
65 100, i ); |
|
66 |
|
67 |
|
68 j = 2000; |
|
69 i = 0; |
|
70 |
|
71 out3: |
|
72 while (i < 1000) |
|
73 { |
|
74 if (i == 100) |
|
75 { |
|
76 j = 0; |
|
77 out4: |
|
78 while (j < 1000) |
|
79 { |
|
80 if (j == 500) break out3; |
|
81 j++; |
|
82 } |
|
83 j = 2001; |
|
84 } |
|
85 j = 2002; |
|
86 i++; |
|
87 } |
|
88 |
|
89 // 'breaking out of a "while" loop with a "label"' |
|
90 new TestCase ( SECTION, 'breaking out of a "while" loop with a "label"', |
|
91 500, j); |
|
92 |
|
93 i = 0; |
|
94 |
|
95 do |
|
96 { |
|
97 if (i == 100) break; |
|
98 i++; |
|
99 } while (i < 1000); |
|
100 |
|
101 // 'breaking out of a "do" loop' |
|
102 new TestCase ( SECTION, 'breaking out of a "do" loop', |
|
103 100, i ); |
|
104 |
|
105 j = 2000; |
|
106 i = 0; |
|
107 |
|
108 out5: |
|
109 do |
|
110 { |
|
111 if (i == 100) |
|
112 { |
|
113 j = 0; |
|
114 out6: |
|
115 do |
|
116 { |
|
117 if (j == 500) break out5; |
|
118 j++; |
|
119 }while (j < 1000); |
|
120 j = 2001; |
|
121 } |
|
122 j = 2002; |
|
123 i++; |
|
124 }while (i < 1000); |
|
125 |
|
126 // 'breaking out of a "do" loop with a "label"' |
|
127 new TestCase ( SECTION, 'breaking out of a "do" loop with a "label"', |
|
128 500, j); |
|
129 |
|
130 test(); |