michael@0: // Labeled break tests. michael@0: function f1() { michael@0: foo: michael@0: if ([1]) { michael@0: bar: michael@0: for (var i=0; i<100; i++) { michael@0: if (i > 60) michael@0: break foo; michael@0: } michael@0: assertEq(0, 1); michael@0: } michael@0: assertEq(i, 61); michael@0: return true; michael@0: } michael@0: assertEq(f1(), true); michael@0: michael@0: // Label with no breaks. michael@0: function f2() { michael@0: foo: michael@0: if ([1]) { michael@0: for (var i=0; i<100; i++) { michael@0: } michael@0: } michael@0: assertEq(i, 100); michael@0: return true; michael@0: } michael@0: assertEq(f2(), true); michael@0: michael@0: // No breaks and early return. michael@0: function f3() { michael@0: foo: { michael@0: if (true) { michael@0: for (var i=0; i<100; i++) { michael@0: } michael@0: } michael@0: return false; michael@0: } michael@0: assertEq(i, 100); michael@0: return true; michael@0: } michael@0: assertEq(f3(), false); michael@0: michael@0: // Multiple breaks. michael@0: function f4() { michael@0: foo: { michael@0: if (true) { michael@0: for (var i=0; i<100; i++) michael@0: if (i > 70) michael@0: break foo; michael@0: if (i > 80) michael@0: break foo; michael@0: } michael@0: break foo; michael@0: } michael@0: assertEq(i, 71); michael@0: return true; michael@0: } michael@0: assertEq(f4(), true);