|
There are several ways to loop, and we will continue with the "while" loop.
The while loop does not have all the nice features of a for loop, and the programmer needs to account for the loop variable initialization prior to the loop body and "manually" increment the loop variables in the loop body.
One reason to choose the while loop is that it need not confine itself to loop variables. The expression can be a function.
The basic form for a do/while loop is:
while ( expression ) { block of code ... }
Example:
work/whileloop.html
<HTML> <BODY> <CENTER> <TABLE BORDER=1 CELLPADDING=6> <SCRIPT LANGUAGE="JavaScript"> var i=0,j=0; // loop variables while (j <= 10) { i=0; j++; document.write('<TR>'); while (i <= 10) { i++ document.write('<TD ALIGN="RIGHT">',i*j,'</TD>'); } document.write('</TR>\n'); // end the line } </SCRIPT> </TABLE> </CENTER> </BODY> </HTML>