A division table : for loop « Statement « PHP






A division table

 
<?php
  $start_num = 1;
  $end_num = 10;
?>
<HTML>
<HEAD>
<TITLE>A division table</TITLE>
</HEAD>
<BODY>
<H2>A division table</H2>
<TABLE BORDER=1>
<?php
  print("<TR>");
  print("<TH> </TH>");
  for ($count_1 = $start_num;$count_1 <= $end_num;$count_1++)
    print("<TH>$count_1</TH>");
  print("</TR>");

  for ($count_1 = $start_num;$count_1 <= $end_num;$count_1++){
    print("<TR><TH>$count_1</TH>");
    for ($count_2 = $start_num;$count_2 <= $end_num;$count_2++){
        $result = $count_1 / $count_2;
        printf("<TD>%.3f</TD>",
               $result);  // see Chapter 108
      }
    print("</TR>\n");
  }
?> 
</TABLE>
</BODY>
</HTML>
  
  








Related examples in the same category

1.For statement without second condition
2.For statement without all three statements
3.For loop: Counting Backwards
4.For loop: Counting By Fives
5.Use for loop to output HTML table
6.For loop format
7.If statement inside a for loop
8.Nesting Two for Loops
9.A for Loop That Divides 4000 by Ten Incremental Numbers
10.Using the for Statement
11.A for Loop That Divides 4000 by Ten Incremental Numbers
12.A for loop in PHP
13.Alternating table row colors with for()
14.Loops Within Loops
15.Iterating through a multidimensional array with for()
16.Iterating through a numeric array with for()
17.Loop goes from 0 to 100 in steps of 0.1
18.Fahrenheit and Celsius table by for loop
19.Specifying a number after break, such as break 2, to break out of two loops or switch/case statements
20.Multiple expressions in for()
21.Nesting Two for Loops
22.Printing a
23.Printing out all the web-safe color codes