JavaScript Tutorial - "do/while" loop

Left
Right

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>

HOMEWORK:

  1. Use the functions F2C() and C2F() defined in a previous assignment and create a conversion table. Use the values 0 to 100 in increments of 2. Display the value, the Celsius conversion (F2C), and the Fahrenheit conversion (C2F).
    You can use either <PRE> or <TABLE> formatting.
Left
Right
Slide 11