do
statement in JavaScript ver. 1.2+ 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 );
// 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.