Practical 3
Practical 3
DEPARTMENTOFCOMPUTERENGINEERING
ExperimentNo: 3
Theory:
1.0Title:
Write a program to demonstrate the use of looping structure using while loop, do….while
loop,forloop
foreach loop
2.0Loopingstatement
3.0NewConcepts:
Proposition1:whilestatement
Itisentrycontrolledloop. Conditionistested attheentryofbody ofloop.
Syntax:while(test-condition)
Body ofloop
}
Proposition 2:do….Whileloop
Syntax:do{
Body of loop
While(test-condition);
Proposition 3:forloop
structureSyntax: for(initialization;test-
condition;increment-section)
Body ofloop
Proposition4:foreachloop
The foreach loop - Loops through a block of code for each element in an
code tobeexecuted;
4.0 LearingOjectives:In
tellectualSkills:
1. Tounderstand the useofwhileloop
2. Tounderstand the useofdo…..whileloop
3. Tounderstand the useofforloop
4. Touseloopingstructure tosolvegivenproblem
MotorSkills:
1. Abilitytouseloopingstatements tosolvegivenproblem.
2. AbilitytousePHP webservers.
5.0 Apparatus:
2 OperatingSystem:Windows/Linux All
3 AnyDatabasetoolsuchasMYSQL,MariaDB 15,16
While Statement:-
Program:-
<?php
$x=1;
while($x<=5)
{
echo "the no is: $x <br>";
$x++;
}
?>
Output:-
Do…..whileloop
Program:-
<?php
$x=1;
do
{
echo "the no is: $x <br>";
$x++;
}
while($x<=5)
?>
Output:-
Forloop
Program:-
<?php
for($x=0;$x<=8;$x++)
{
echo"thenois:$x<br>";
}
?>
Output:-
Foreachloop
Program:-
<?php
$book=array("html","python","java","php");for
each($book as $value)
{
echo"$value<br>";
}
?>
Output:-