PHP For Loops
- What will be the output of the following PHP code ?
<?php
for ($d = 0; -7 ; $d++)
{
print"d";
if ($d == 4)
break;
}
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: E
The break statement after breaks the loop after d = 4,does not print anymore.
- What will be the output of the following PHP code ?
<?php
for ($g = 0; 0; $g++)
{
print"g";
}
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
The condition of the loop is always false 0.
- What will be the output of the following PHP code ?
<?php
for ($v = 0; $v < 5; $v++)
{
for ($u = $v; $u > 0; $v--)
print $v;
}
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
In the second loop u value is not being changed.
- What will be the output of the following PHP code ?
<?php
for($g = 0; $g < 15; $g++)
{
for($h = $g; $h > $g; $g--)
print $g;
}
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
The second loop does not execute as the check condition is always false.
- What will be the output of the following PHP code ?
<?php
$emp = array("Ajit", "Ats", "Aju","Rahul");
for ($p = 0; $p < count($emp); $p++)
{
if ($emp[$p] == "Rahul")
continue;
printf ($emp[$p]);
}
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: E
Only the Shrek is skipped due to the continue statement.