Practical 13 : Write a PHP program which is execute while and do. while loop
<html>
<head>
<title>Practical : 13</title>
</head>
<body>
<br>
<br>
<center>
<?php
$no='';
$sum='';
if(isset($_POST['ok']))
{
$i=1;
$no = $_POST['t1'];
//============== Using While Loop =============
while($i<=$no)
{
$sum = $sum + $i;
$i++;
}
//============== Using Do-While Loop =============
do
{
$sum = $sum + $i;
$i++;
}while($i<=$no);
//============== Using For Loop =============
for($i=1;$i<=$no;$i++)
{
$sum = $sum + $i;
}
}
?>
<form name="f1" method="post">
<table>
<tr>
<td>Enter No. :</td>
<td><input type="text" name="t1" value="<?php echo $no; ?>"></td>
</tr>
<tr>
<td>Sum of The No.:</td>
<td>
<input type="text" name="t2" value="<?php echo $sum; ?>">
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="ok" value="Click Me">
</td>
</tr>
</table>
</form>
</center>
</body>
</html>

EmoticonEmoticon