Basically "PHP" has 3 kinds of loop, namely, "for" statement, "while" statement, and "do ... while" statement. Below we learn on "for" statement.
The regular expression of "for" statement is like this:
for (initialization; condition(s) or bound(s); increment or decrement) {
// code to be executed
}
The expressions within the parentheses of the "for" statement are separated by semicolons. Usually, the first expression initializes an $i (as a counter) variable, the second expression is the test condition for the loop, and the third expression increments or decrements the counter depending on the condition given. Below we go directly to the example:
<?php
for ($i=1; $i<=10; $i++) {
echo "$i * 10 = ".($i * 10)."<br />";
}
?>
save it as loopfor1.php and open via your browser. The result should be like this:
1 * 10 = 10
2 * 10 = 20
3 * 10 = 30
4 * 10 = 40
5 * 10 = 50
6 * 10 = 60
7 * 10 = 70
8 * 10 = 80
9 * 10 = 90
10 * 10 = 100
One thing to watch in "for" statement is that "dont forget to write the condition(s) expression" to stop looping so that the program will not loop infinitely.
The regular expression of "for" statement is like this:
for (initialization; condition(s) or bound(s); increment or decrement) {
// code to be executed
}
The expressions within the parentheses of the "for" statement are separated by semicolons. Usually, the first expression initializes an $i (as a counter) variable, the second expression is the test condition for the loop, and the third expression increments or decrements the counter depending on the condition given. Below we go directly to the example:
<?php
for ($i=1; $i<=10; $i++) {
echo "$i * 10 = ".($i * 10)."<br />";
}
?>
save it as loopfor1.php and open via your browser. The result should be like this:
1 * 10 = 10
2 * 10 = 20
3 * 10 = 30
4 * 10 = 40
5 * 10 = 50
6 * 10 = 60
7 * 10 = 70
8 * 10 = 80
9 * 10 = 90
10 * 10 = 100
One thing to watch in "for" statement is that "dont forget to write the condition(s) expression" to stop looping so that the program will not loop infinitely.
.jpg)
BCS examination is one of the most perfect ways of getting a job in Public service commissions. Most of the Bangladeshi students allow themselves with a job of PSC. But the preparation is of the huge amount and takes a lot of time. As the number of seats is less than the number of candidates, the examination is very competitive and becomes a war field for people. Here are 10 special tips provided for BCS examination.









