PHP While Loops
- What will be the output of the following PHP code ?
<?php
$m = 5;
while (++$m)
{
while ($m > 0)
print $m;
}
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: E
The loop never ends as m is always incremented and then decremented.
- What will be the output of the following PHP code ?
<?php
$p = 5;
while($p = 20)
{
print "INDIA";
}
print "USA";
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
While condition always gives 1.
- What will be the output of the following PHP code ?
<?php
$s = "";
while ($s = 20)
{
print "Interveiw";
}
print "Mania";
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
While condition always gives 1.
- What will be the output of the following PHP code ?
<?php
$p = 10;
while (--$p > 0)
{
$p++;
print $p;
print "INDIA";
}
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
p is decremented in the first while execution and then continuously incremented back.
- What will be the output of the following PHP code ?
<?php
$k = 15;
while (--$k > 0 && ++$k)
{
print $k;
}
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
As it is && operator it is being incremented and decremented continuously.