Page 102 - PortGPT_V2.1_C8_Flipbook
P. 102
The preceding code will display the numbers from 1 to 4. Let us create a web page to use the while
loop.
Program 2: To display the first 10 even numbers on the web page by using the while loop.
<HTML>
<HEAD>
<TITLE> Using while Loop </TITLE>
</HEAD>
<BODY>
<H3> Using while Loop to Display First 10 Even Numbers Starting from 0
</H3>
<SCRIPT>
var i=1;
while(i<=20)
{
if(i%2==0)
{
document.write(i+"<BR>");
}
i++;
}
</SCRIPT>
</BODY>
</HTML>
The output of the Program 2 is shown below:
100 Premium Edition-VIII

