PHP While Loops
- What will be the output of the following PHP code ?
<?php
$p = 0;
while ($p++)
{
print $p;
}
print $p;
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
As it is a post increment, it checks and then does not enter the loop, thus prints only 1.
- What will be the output of the following PHP code ?
<?php
$k = 10;
while ($k < 30)
{
$k++;
}
print $k;
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
The increment happens and then the check happens.
- What will be the output of the following PHP code ?
<?php
$t = 20;
do
{
$t++;
}
while ($t < 60);
print $t;
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
The increment happens and then the check happens.
- What will be the output of the following PHP code ?
<?php
$num = 2;
while ($num < 5)
{
print "Interview";
$num--;
}
print "Mania";
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
There is no increment of num making it infinite.
- What will be the output of the following PHP code ?
<?php
$n = "";
while($n)
{
print "Manjesh";
}
print "Ojha";
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
While accept does not accept anything other than a 0 or any other number as false and true.