for Loop in PHP
Notes:
PHP Looping / Iterative Statements:
- To execute one or more statements repeatedly, we use looping or iterative statements.
for loop,
while loop,
do while loop,
foreach as loop
for loop: Entry control loop:
PHP engine executes statement(s) inside the for loop, until the given conditional expression evaluates to false.
Syntax:
for(initialization; conditional expression; increment/decrement)
{
statement(s);
}
OR
for(initialization; conditional expression; increment/decrement):
statement(s);
endfor;
Ex:
for( $counter=0; $counter<5; $counter++ )
{
echo "Hello World","<br/>";
}
OR
for( $counter=0; $counter<5; $counter++ ):
echo "Hello World","<br/>";
endfor;
Note: When you know exactly how many # of times the loop is going to get execute, use for loop.
Interview Questions:
1. PHP stands for ______________
a. Hypertext Preprocessor
b. Preprocessor Hypertext
c. Personal Home Processor
d. Personal Hypertext processor
Ans: a