ExamVeda
Login
Home
61
What will be the output of the following PHP code ?
<?php
for ($x = 0; $x <= 10; print ++$x)
{
    print ++$x;
}
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
The value of x is incremented and printed twice before checking,thus last loop it prints 11 and 12.
62
What will be the output of the following PHP code ?
<?php
for ($x =1; $x < 10;++$x)
{
    print "*t";
}
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
Loop runs from 1 to 9 i.e 9 times.
63
What will be the output of the following PHP code ?
<?php
for ($x = -1; $x < 10;--$x)
{
    print $x;
}
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
The value of x is decremented thus making it an infinite loop.
64
What will be the output of the following PHP code ?
<?php
$x;
for ($x = -3; $x < -5; ++$x)
{
    print ++$x;
}
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
The loop is not even entered as x is initially 0.
65
What will be the output of the following PHP code ?
<?php
for ($i++; $i == 1; $i = 2)
    print "In for loop ";
    print "After loopn";
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
The loop runs only once as value of x is incremented.
66
What will be the output of the following PHP code ?
<?php
for (1; $i == 1; $i = 2)
    print "In for loop ";
    print "After loopn";
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
The loop does not run as i initialized in check statement will be zero.
67
What will be the output of the following PHP code ?
<<php
for ($i == 2; ++$i == $i; ++$i)
    print "In for loop ";
    print "After loopn";
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
The loop never exits as the condition ++X == X is always satisfied,evaluated from right to left.
68
What will be the output of the following PHP code ?
<?php
for ($x = 1; $x < 10; $x++)
    for ($y = 1; $y < 5; $y++)
        print "Hello";
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
9*4 times is printed.
69
What will be the output of the following PHP code ?
<?php
for ($count = 1; $count != 20;$count++)
{
    print $count;
    $count++;
}
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
Condition always fails as count takes only odd numbers.
70
What will be the output of the following PHP code ?
<?php
for ($count = 1; $count < 20; $count++);
    print $count;
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
The for loop has no body,it just runs till condition is satisfied.