Last renewed!
These days I found that some children's shoes still have some problems in outputting the multiplication table. Today I will give you a detailed explanation...
First, let's look at the Code:
<? Php
For ($ I = 1; $ I <= 9; $ I ++ ){
For ($ j = 1; $ j <= $ I; $ j ++ ){
Echo "$ j x $ I =". $ j * $ I ."";
}
Echo "<br> ";
}
?>
Output result:
Well, let's further analyze:
We call the outermost loop a "Trip ":
First trip:
$ I is 1, meeting $ I <= 9,
While the inner loop $ j satisfies $ j <= $ I and outputs 1x1 = 1.
$ J auto-increment 1, no longer meet $ j <= $ I, no output
Output "<br/>" line feed,
$ I auto-increment 2
This trip ends.
Second trip:
If $ I is 2 and $ I <= 9 is met, the second loop is executed.
The condition of the inner loop becomes:
For ($ j = 1; $ j <= 2; $ j ++ ){
........
}
The inner layer loops output twice, respectively:
1x2 = 2 and 2x2 = 4
Similarly, when $ j in the inner loop is added to 3, the inner loop is no longer executed.
Output "<br> ";
$ I auto-increment is 3
This trip is over!
Third trip:
Same as above .....
And so on:
Until the Ninth:
$ I has been added as 9
$ I <= 9 is still valid
Execute the inner loop of the ninth round:
At this time, the inner loop changes
For ($ j = 1; $ j <= 9; $ j ++ ){
...........
}
The code in the loop body is executed cyclically 9 times,
Are
1x9 = 1 2x9 = 18 ...... 9 = 81
That is, the last line of the result.
At this time, $ j no longer meets $ j <= 9, and the execution of the inner loop ends.
Output "<br/>"
$ I auto-increment is 10
This trip ends.
By the time of the tenth round, $ I is 10 and no longer meets $ I <= 9. At this point, this Round Robin will not be executed.
The displayed 9-9 multiplication table is output.
I don't know if you understand it. If you understand it, try to output the 9-9 multiplication table in turn! The principle is the same!
Author: zdrjlamp