![]() |
|
![]() |
There are several ways to loop, and we will continue with the "do/while" loop.
The primary feature of do/while loops is that it the statements is executed as least once, regardless of the condition.
However, all the variable initialization needs to be done prior to the do/while loop, and incrementing must done within the body of the do/while loop.
The basic form for a do/while loop is:
do {
block of code ...
} while ( expression );
Example:
work/dowhile.html
<HTML>
<BODY>
<CENTER>
<TABLE BORDER=1 CELLPADDING=6>
<SCRIPT LANGUAGE="JavaScript">
var i,j=0; // loop variables
do {
i=0;
j++;
document.write('<TR>');
do {
i++
document.write('<TD ALIGN="RIGHT">',i*j,'</TD>');
} while (i < 10);
document.write('</TR>\n'); // end the line
} while (j < 10);
</SCRIPT>
</TABLE>
</CENTER>
</BODY>
</HTML>