0% found this document useful (0 votes)
3 views

Php Practical 3

The document provides a PHP program demonstrating the use of looping structures, specifically for, while, and do..while loops to print the first 30 even numbers. It also includes exercises that utilize if conditions with for loops to identify odd and even numbers, as well as programs to display star patterns in a pyramid format. The author of the document is Atharv Kharbale, with roll number 16(A).

Uploaded by

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

Php Practical 3

The document provides a PHP program demonstrating the use of looping structures, specifically for, while, and do..while loops to print the first 30 even numbers. It also includes exercises that utilize if conditions with for loops to identify odd and even numbers, as well as programs to display star patterns in a pyramid format. The author of the document is Atharv Kharbale, with roll number 16(A).

Uploaded by

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

Practical No: 03

Write a PHP program to demonstrate the use of Looping structures.

Name: Atharv Kharbale

Roll.no: 16(A)

Q. Write a program to print first 30 even numbers. (Using for, while, do..while)

FOR LOOP:

<?php
for ($i = 0; $i <=60; $i=$i+2)
{
echo $i ," ";}
?>

WHILE LOOP:

<?php $n = 1;
while ($n <= 60)
{
if ($n % 2 == 0)
{
echo "$n<br>";
}
$n++;
}
?>
DO----WHILE LOOP:

<?php $n = 1;
do {
if ($n % 2 == 0)
{
echo "$n<br>";
}
$n++;
} while ($n <= 60);
?>
XI. Exercise

1. Write any program using if condition with for loop.

<?php
for($i=1;$i<=10;$i++)
{
$num=$i;
print "</br>";
if($num % 2==1)
{
print($num.": Number is Odd");
}
else
{
print($num.": Number is Even");
}
}
?>

2. Write a program to display pyramids of star patterns using increment/decrement.

<?php
$n = 5;
for ($i = 1; $i <= $n; $i++) {
for ($j = 1; $j <= $i; $j++) {
echo "*";
}
echo "<br>";
}
?>
<?php
$n = 5;
for ($i = $n; $i >= 1; $i--) {
for ($j = 1; $j <= $i; $j++) {
echo "*";
}
echo "<br>";
}
?>

You might also like