The do statement in JavaScript ver. 1.2+

An equivalent for lower versions of browsers

( e.g. Netscape Navigator 2.0-3.X, Internet Explorer 3.X )


The JavaScript 'do' statement was only implemented by JavaScript version 1.2,   on Netscape's Navigator ( and MS's Explorer ) browsers of version 4.    It takes the form :

do {

     statements

} while ( expression );



  In JavaScript versions 1.0 & 1.1, the following replacement works the same way:


// START_DO_EQUIV:     a 'do / while' equivalent for NN2-3 and IE3

statements

while ( expression ) {

     statements

}
// NB: there are 2 IDENTICAL copies of 'statements' here.
// END_DO_EQUIV:



Something to look out for in this replacement:   In the first copy of 'statements', any use of continue and break will act differently! and will likely require rewriting of that first 'statements' block of code.

You see, any use of 'continue' in that area is not within the subsequent while block... so there is not necessarily anything to continue! Instead, code must be inserted that will skip the rest of the first 'statements' block, to the while's beginning.

As for any use of 'break' in the first 'statements' block:  It can have continue substituted for it  -  but only if the do / while is immediately surrounded by a loop statement (for or while).  If that is not the case (if there is no immediately enclosing loop) then one has to somehow skip the rest of the code all the way to the end of the while.   Tough luck! And so hard to do that you'd better, for JavaScript version 1.0 or 1.1, just to redo program logic completely to eliminate the need for anything like a do structure.

   [ R. Hess, BrainBench.com certified Master JavaScript Programmer, September 11 2000. ]
logo, of Brainbench.com certification, Russell Hess being a certified Master JavaScript Programmer

- Page created September 11-12, 2000 (& tweaked August 7 2001) by Russell Hess, Webmaster (hess1@bigfoot.com) of 'UpSky2' & 'UpSky'; JavaScript programming and HTML page design by 'UpSky'.

                       
logo of the UpSky websites