PHP Loop MCQs

11. What will be the output of the following PHP code ?

<?php
    do
    {
          print "LFC";
    }
    while(10);
    print "I LOVE WEBSITE";
?>

A. LFC
B. I LOVE WEBSITE
C. LFC I LOVE WEBSITE
D. infinite loop

View Answer


12. What will be the output of the following PHP code ?

<?php
   $a;
   for ($a = -3; $a < -5; ++$a)
   {
        print $x++;
   }
?>

A. -3-4-5
B. -3-4
C. No Output
D. infinite loop

View Answer


13. What will be the output of the following PHP code ?

<?php
for ($a = 1; $a <= 10; $a++){
    for ($b = 1; $b <= 5; $b++){
        print "LFC
";
    }
}
?>

A. Print "LFC" 10 times
B. Print "LFC" 50 times
C. Print "LFC" 5 times
D. Print "LFC" 1 times

View Answer


14. What will be the output of the following PHP code ?

<?php
for($num = 10; $num<=20; print ++$num)
  {
      print ++$num;
  }
?>

A. 111213141516171819202122
B. 11121314151617181920
C. 1112131415161718192021
D. infinite loop

View Answer


15. What will be the output of the following PHP code ?

<?php
$i=-5;
while($i){
        $i++;
        if($i%2==0)
                continue;
        else
        {
                $i++;
        }
       echo($i);
}
?>

A. 4 to 20
B. -20
C. Null
D. infinite loop

View Answer


16. What will be the output of the following PHP code ?

<?php
for ($i = 0; $i < 4; $i++)
{
  for ($j = 0; $j < 3; $j++)
  {
   if ($i > 1)
   continue;
   echo("Hi 
");
  }
}
?>

A. prints "Hi" 3 times
B. prints "Hi" 4 times
C. prints "Hi" 5 times
D. prints "Hi" 6 times

View Answer


17. What will be the output of the following PHP code ?

<?php
$i = 0;
$j = 0;
first: while ($i < 2)
{
 $i++;
  while ($j < 3)
    {
     $j++;               
      echo("loop
");
      if($j%2==0)
         continue;
      goto first;
    }
}
?>

A. prints "loop" infinite times
B. prints "loop" 1 times
C. prints "loop" 2 times
D. prints "loop" 3 times

View Answer


18. What will be the output of the following PHP code ?

<?php
for($i=0; $i<=5; $i++){
    $i = $i+1;
}

echo "$i";
?>

A. 5
B. 6
C. 7
D. 8

View Answer


19. What will be the output of the following PHP code ?

<?php
$a = 10;
$b = $a>2?"Hi":"Bye";
echo "$b";
?>

A. HiBye
B. Bye
C. Hi
D. Error

View Answer


20. What will be the output of the following PHP code ?

<?php
$a = 0;
if($a > 1 );
{
  echo "Sun";   
}
echo "Moon";
?>

A. SunMoon
B. Sun
C. Moon
D. Error

View Answer





Discussion


* You must be logged in to add comment.