0% found this document useful (0 votes)
25 views2 pages

Practical No 03 PHP

The document contains PHP code examples demonstrating different types of loops: a while loop for printing even numbers, a do-while loop for printing odd numbers, a for loop for printing even numbers and calculating their sum, and a foreach loop for iterating over an array. Each section of code outputs values to the browser. The code illustrates basic control structures in PHP programming.

Uploaded by

zubiyaansari417
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views2 pages

Practical No 03 PHP

The document contains PHP code examples demonstrating different types of loops: a while loop for printing even numbers, a do-while loop for printing odd numbers, a for loop for printing even numbers and calculating their sum, and a foreach loop for iterating over an array. Each section of code outputs values to the browser. The code illustrates basic control structures in PHP programming.

Uploaded by

zubiyaansari417
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

PRACTICAL NO: 03

<?php
//while loop to print even numbers
$i=0;
while ($i<= 10)
{
echo "$i<br/>";
$i+=2;
}
?>

<?php
//do-while loop to print odd numbers
$i=1;
do
{
echo "$i<br/>";
$i+=2;
}while ($i< 10);
?>
<?php
//for loop to print even numbers and
sum of them
$sum=0;
for($i=0; $i<=10;$i+=2)
{
echo "$i<br/>";
$sum+=$i;
}
echo "Sum=$sum";
?>

<?php
$arr = array (10, 20, 30, 40, 50);
foreach ($arr as $i)
{
echo "$i<br/>";
}
?>

You might also like