Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 102 - 2625 PortGPt V2.1
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

| 97 98 99 100 101 102 103 104 105 106 107 |