Searching...
Monday 17 September 2012

Php Loops OR Control Statements

10:28 pm

Php Loops OR Control Statements

Php Loops OR Control Statements :

 there are four types of Php Loops OR Control Statements :

1.       While loop
2.       Do while loop
3.       For loop
4.       Foreach  loop

1.       Write a Programe to display the first 10 natural numbers by using While loop ?
<?php
Echo “first 10 natural numbers are : <br>”;
$x = 1;
While ($x<=10)
{
Echo $x. “<br>”;
$x = $x+1;
}
?>
2.       Write a programe to display first 10 even numbers by using While loop?
<?php
$x = 2;
While ($x<=20)
{
   Echo $x. “<br>”;
   $x = $x + 2;
}
?>
3.       Write a programe to display the multiplication table of a number by using for loop?

    5  *  1 = 5
    5  *   2 = 10
    5  *  3 = 15
    -------------
    -------------
    5  *  10  = 50
<?php
$x = 5;
For ($y=1; $y<=10;$y++)
{
 $z = $x * $y;
 Echo $x. “*” .$y.”=” .$z.”<br>”;
}
?>

0 comments:

Post a Comment