ExamVeda
Login
Home
71
What will be the output of the following PHP code ?
<?php
for ($count = 0; $count < 3;$count++);
{
    print "hi";continue;print "hello";
}
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
When continue is encountered it skips to the next iteration
72
What will be the output of the following PHP code ?
<?php
for ($count = 0; $count<3;$count++);
{
    print "hi";break;print "hello";
}
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
When break is encountered it leaves the loop.
73
What will be the output of the following PHP code ?
<?php
for(++$i; ++$i; ++$i)
{
    print $i;
    if ($i == 4) 
        break;
}
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
The order of execution is initialization, check, increment/decrement, check, increment/decrement, check, increment/decrement….so on.
74
What will be the output of the following PHP code ?
<?php
for ($i = 0;$i = -1;$i = 1)
{
    print $i;
    if ($i != 1) 
	break;
}
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
The order of execution is initialization, check, increment/decrement, check, increment/decrement, check, increment/decrement….so on .
75
What will be the output of the following PHP code ?
<?php
for(;;)
{
   print "10";
}
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
There is no check condition to stop the execution of the loop.
76
What will be the output of the following PHP code ?
<?php
for ($i = 0; -5 ; $i++)
{
    print"i";
    if ($i == 3)
        break;
}
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
The break statement after breaks the loop after i=3,does not print anymore.
77
What will be the output of the following PHP code ?
<?php
for ($i = 0; 0; $i++) 
{
    print"i";
}
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
The condition of the loop is always false 0.
78
What will be the output of the following PHP code ?
<php
for ($i = 0; $i < 5; $i++) 
{
    for ($j = $i; $j > 0; $i--)
        print $i;
}
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
In the second loop j value is not being changed.
79
What will be the output of the following PHP code ?
<?php
for ($i = 0; $i < 5; $i++)  
{
    for ($j = $i;$j > $i; $i--)
        print $i;
}
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
The second loop does not execute as the check condition is always false.
80
What will be the output of the following PHP code ?
<?php
$user = array("Ashley", "Bale", "Shrek", "Blank");
for ($x = 0; $x < count($user); $x++) 
{
    if ($user[$x] == "Shrek") 
	    continue;
    printf ($user[$x]); 
}
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
Only the Shrek is skipped due to the continue statement.