For Loop
- PHP for loop can be used to traverse set of code for the specified number of times.
- It should be used if number of iteration is known otherwise use while loop
- Syntax:-
//code to be executed
}
Example:-
<?php
for($n=1;$n<=10;$n++){
echo “$n<br/>”;
}
?>
OUTPUT:-
1
2
3
4
5
6
7
8
9
10
While Loop use in PhP
- while loop can be used to traverse set of code like for loop.
- it should be used if number of iteration is not known.
while(condition){
//code to be executed
}
another syntax:-//code to be executed
}
while(condition):
//code to be executed
endwhile;
//code to be executed
endwhile;
Example:-
<?php
$n=1;
while($n<=10){
echo “$n”;
0 Comments:
Post a Comment