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

WBP22202A0023PR03

Uploaded by

guyn9074
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)
11 views

WBP22202A0023PR03

Uploaded by

guyn9074
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/ 3

IF6IA WBP

DEPARTMENT OF INFORMATION TECHNOLOGY

Subject: Web based Application Development Subject Code: 22619


using PHP
Semester: 6th Course: IF6IA
Laboratory No: L001 Name of Teacher: Chetashri Bhusari
Name of Student: Prajwal Patekar Roll ID: 2220A0023

Experiment No: 3
Title of Experiment Write a PHP program to demonstrate the use of looping structures using:
a) While statement
b) Do-while statement
c) For statement
d) Foreach statement

☆ Practical Related Questions


1. When for loop will be terminated?

Ans: A for loop will terminate when the condition specified in the loop evaluates to false.

2. Difference between for and foreach loop.


Ans:

22202A0023 Prajwal Patekar


IF6IA WBP

☆ Exercise

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

Ans:
<?php
echo "<h3>Even Numbers from 1 to 10</h3>";
for ($i = 1; $i <= 10; $i++) {
if ($i % 2 == 0) { // Check if number is even
echo "$i is even <br>";
}
}
?>
Output:

2. Write a program to check whether a number is positive or negative.

Ans:
1.Increment
<?php
$n = 5; // Number of rows
for ($i = 1; $i <= $n; $i++) {
for ($j = 1; $j <= $i; $j++) {
echo "* ";
}
echo "<br>";
}
?>

22202A0023 Prajwal Patekar


IF6IA WBP

2.Decrement
<?php
$n = 5; // Number of rows
for ($i = $n; $i >= 1; $i--) {
for ($j = 1; $j <= $i; $j++) {
echo "* ";
}
echo "<br>";
}
?>

Output:

22202A0023 Prajwal Patekar

You might also like