Home | History | Annotate | Download | only in Statements
      1 /**
      2  *  File Name:          dowhile-006
      3  *  ECMA Section:
      4  *  Description:        do...while statements
      5  *
      6  *  A general do...while test.
      7  *
      8  *  Author:             christine (at) netscape.com
      9  *  Date:               26 August 1998
     10  */
     11     var SECTION = "dowhile-006";
     12     var VERSION = "ECMA_2";
     13     var TITLE   = "do...while";
     14 
     15     startTest();
     16     writeHeaderToLog( SECTION + " "+ TITLE);
     17 
     18     var tc = 0;
     19     var testcases = new Array();
     20 
     21     DoWhile( new DoWhileObject( false, false, 10 ) );
     22     DoWhile( new DoWhileObject( true, false, 2 ) );
     23     DoWhile( new DoWhileObject( false, true, 3 ) );
     24     DoWhile( new DoWhileObject( true, true, 4 ) );
     25 
     26     test();
     27 
     28 function looping( object ) {
     29     object.iterations--;
     30 
     31     if ( object.iterations <= 0 ) {
     32         return false;
     33     } else {
     34         return true;
     35     }
     36 }
     37 function DoWhileObject( breakOut, breakIn, iterations, loops ) {
     38     this.iterations = iterations;
     39     this.loops = loops;
     40     this.breakOut = breakOut;
     41     this.breakIn  = breakIn;
     42     this.looping  = looping;
     43 }
     44 function DoWhile( object ) {
     45     var result1 = false;
     46     var result2 = false;
     47 
     48     outie: {
     49         innie: {
     50             do {
     51                 if ( object.breakOut )
     52                     break outie;
     53 
     54                 if ( object.breakIn )
     55                     break innie;
     56 
     57             } while ( looping(object) );
     58 
     59             //  statements should be executed if:
     60             //  do...while exits normally
     61             //  do...while exits abruptly with no label
     62 
     63             result1 = true;
     64 
     65         }
     66 
     67         //  statements should be executed if:
     68         //  do...while breaks out with label "innie"
     69         //  do...while exits normally
     70         //  do...while does not break out with "outie"
     71 
     72         result2 = true;
     73     }
     74 
     75     testcases[tc++] = new TestCase(
     76         SECTION,
     77         "hit code after loop in inner loop",
     78         ( object.breakIn || object.breakOut ) ? false : true ,
     79         result1 );
     80 
     81     testcases[tc++] = new TestCase(
     82         SECTION,
     83         "hit code after loop in outer loop",
     84         ( object.breakOut ) ? false : true,
     85         result2 );
     86 }
     87