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: * File Name: dowhile-006 michael@0: * ECMA Section: michael@0: * Description: do...while statements michael@0: * michael@0: * A general do...while test. michael@0: * michael@0: * Author: christine@netscape.com michael@0: * Date: 26 August 1998 michael@0: */ michael@0: var SECTION = "dowhile-006"; michael@0: var VERSION = "ECMA_2"; michael@0: var TITLE = "do...while"; michael@0: michael@0: startTest(); michael@0: writeHeaderToLog( SECTION + " "+ TITLE); michael@0: michael@0: DoWhile( new DoWhileObject( false, false, 10 ) ); michael@0: DoWhile( new DoWhileObject( true, false, 2 ) ); michael@0: DoWhile( new DoWhileObject( false, true, 3 ) ); michael@0: DoWhile( new DoWhileObject( true, true, 4 ) ); michael@0: michael@0: test(); michael@0: michael@0: function looping( object ) { michael@0: object.iterations--; michael@0: michael@0: if ( object.iterations <= 0 ) { michael@0: return false; michael@0: } else { michael@0: return true; michael@0: } michael@0: } michael@0: function DoWhileObject( breakOut, breakIn, iterations, loops ) { michael@0: this.iterations = iterations; michael@0: this.loops = loops; michael@0: this.breakOut = breakOut; michael@0: this.breakIn = breakIn; michael@0: this.looping = looping; michael@0: } michael@0: function DoWhile( object ) { michael@0: var result1 = false; michael@0: var result2 = false; michael@0: michael@0: outie: { michael@0: innie: { michael@0: do { michael@0: if ( object.breakOut ) michael@0: break outie; michael@0: michael@0: if ( object.breakIn ) michael@0: break innie; michael@0: michael@0: } while ( looping(object) ); michael@0: michael@0: // statements should be executed if: michael@0: // do...while exits normally michael@0: // do...while exits abruptly with no label michael@0: michael@0: result1 = true; michael@0: michael@0: } michael@0: michael@0: // statements should be executed if: michael@0: // do...while breaks out with label "innie" michael@0: // do...while exits normally michael@0: // do...while does not break out with "outie" michael@0: michael@0: result2 = true; michael@0: } michael@0: michael@0: new TestCase( michael@0: SECTION, michael@0: "hit code after loop in inner loop", michael@0: ( object.breakIn || object.breakOut ) ? false : true , michael@0: result1 ); michael@0: michael@0: new TestCase( michael@0: SECTION, michael@0: "hit code after loop in outer loop", michael@0: ( object.breakOut ) ? false : true, michael@0: result2 ); michael@0: }