michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: /** michael@0: Filename: break.js michael@0: Description: 'Tests the break statement' michael@0: michael@0: Author: Nick Lerissa michael@0: Date: March 18, 1998 michael@0: */ michael@0: michael@0: var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; michael@0: var VERSION = 'no version'; michael@0: startTest(); michael@0: var TITLE = 'statements: break'; michael@0: michael@0: writeHeaderToLog("Executing script: break.js"); michael@0: writeHeaderToLog( SECTION + " "+ TITLE); michael@0: michael@0: var i,j; michael@0: michael@0: for (i = 0; i < 1000; i++) michael@0: { michael@0: if (i == 100) break; michael@0: } michael@0: michael@0: // 'breaking out of "for" loop' michael@0: new TestCase ( SECTION, 'breaking out of "for" loop', michael@0: 100, i); michael@0: michael@0: j = 2000; michael@0: michael@0: out1: michael@0: for (i = 0; i < 1000; i++) michael@0: { michael@0: if (i == 100) michael@0: { michael@0: out2: michael@0: for (j = 0; j < 1000; j++) michael@0: { michael@0: if (j == 500) break out1; michael@0: } michael@0: j = 2001; michael@0: } michael@0: j = 2002; michael@0: } michael@0: michael@0: // 'breaking out of a "for" loop with a "label"' michael@0: new TestCase ( SECTION, 'breaking out of a "for" loop with a "label"', michael@0: 500, j); michael@0: michael@0: i = 0; michael@0: michael@0: while (i < 1000) michael@0: { michael@0: if (i == 100) break; michael@0: i++; michael@0: } michael@0: michael@0: // 'breaking out of a "while" loop' michael@0: new TestCase ( SECTION, 'breaking out of a "while" loop', michael@0: 100, i ); michael@0: michael@0: michael@0: j = 2000; michael@0: i = 0; michael@0: michael@0: out3: michael@0: while (i < 1000) michael@0: { michael@0: if (i == 100) michael@0: { michael@0: j = 0; michael@0: out4: michael@0: while (j < 1000) michael@0: { michael@0: if (j == 500) break out3; michael@0: j++; michael@0: } michael@0: j = 2001; michael@0: } michael@0: j = 2002; michael@0: i++; michael@0: } michael@0: michael@0: // 'breaking out of a "while" loop with a "label"' michael@0: new TestCase ( SECTION, 'breaking out of a "while" loop with a "label"', michael@0: 500, j); michael@0: michael@0: i = 0; michael@0: michael@0: do michael@0: { michael@0: if (i == 100) break; michael@0: i++; michael@0: } while (i < 1000); michael@0: michael@0: // 'breaking out of a "do" loop' michael@0: new TestCase ( SECTION, 'breaking out of a "do" loop', michael@0: 100, i ); michael@0: michael@0: j = 2000; michael@0: i = 0; michael@0: michael@0: out5: michael@0: do michael@0: { michael@0: if (i == 100) michael@0: { michael@0: j = 0; michael@0: out6: michael@0: do michael@0: { michael@0: if (j == 500) break out5; michael@0: j++; michael@0: }while (j < 1000); michael@0: j = 2001; michael@0: } michael@0: j = 2002; michael@0: i++; michael@0: }while (i < 1000); michael@0: michael@0: // 'breaking out of a "do" loop with a "label"' michael@0: new TestCase ( SECTION, 'breaking out of a "do" loop with a "label"', michael@0: 500, j); michael@0: michael@0: test();