0
2.5kviews
Explain Control structures in PHP
written 7.8 years ago by | • modified 7.8 years ago |
Mumbai University > Information Technology > Sem 4 > Web Programming
Marks: 10M
Year: Dec 2014
ADD COMMENT
EDIT
1 Answer
written 7.8 years ago by | • modified 7.8 years ago |
Mumbai University > Information Technology > Sem 4 > Web Programming
Marks: 10M
Year: Dec 2014
written 7.8 years ago by |
These are
1) Selection Statements:
Switch Case is also used for multiple choices.
<html>
<head>
<title> Selection Demo</title>
</head>
<body>
<?php
Print “<h2> Selection Statement<h2>”;
$a=10;
$b=20;
$c=30;
if($a>$b)
if($a>$c)
print “\ltb\gt\ltI\gta is largest number\lt/I\gt\lt/b\gt”;
else
print “\ltb\gt\ltI\gt c is the largest number\lt/I\gt\lt/b\gt”;
else
if($b>$c)
print “\ltb\gt\ltI\gt b is the largest number \lt/I\gt\lt/b\gt”;
else
print “\ltb\gt\ltI\gt c is the largest number\lt/I\gt\lt/b\gt”;
?\gt
\lt/body\gt
\lt/html\gt
**Output:**
Selection Statement
C is the largest number
2) **Loop Statements**
- The loops statements consists of while, do while and for statements. Loops statements are used to perform repetitive tasks.
While Example:
\lt?php
$i=1;
print “The numbers are…”
print “<br/>”;
while($i\lt=5)
{
print $i;
print “<br/>
$i++;
}
?\gt
**Output:**
The numbers are…
1
2
3
4
5
**do ..while Example:**
\lt?php
$i=1;
print “The numbers are…”;
print “
”;
dp
{
print $i;
print “\ltbr/\gt”;
$i++;
}while($i\lt=5
);
?\gt
**for Example:**
\lt?php
print “The numbers are..”;
print “\ltbr/\gt”;
for($i=1;$i\ltn)
{
print $i;
print “
”;
$i++;
}
?>