Loops
1.

What will be the output of the following PHP code?

<?php
$i = 0;
for ($i)
{
    print $i;
}
?>
A.  

0

B.  

infinite loop

C.  

no output

D.  

error

2.

What will be the output of the following PHP code?

<?php
$colors = array("red","green","blue","yellow"); 
foreach ($colors as $value)
{
    echo "$value <br>";
}
?>
A.  
red 
  
green 

  blue 

  yellow
B.  

red

C.  

no output

D.  

error

3.

What will be the output of the following PHP code?

<?php
for ($x = 0; $x <= 10; $x++)
{
    echo "The number is: $x <br>";
}
?>
A.  
The number is: 0 
The number is: 1 
The number is: 2 
The number is: 3 
The number is: 4 
The number is: 5 
The number is: 6 
The number is: 7 
The number is: 8 
The number is: 9 
The number is: 10
B.  

The number is: 0

C.  

no output

D.  

error

4.

What will be the output of the following PHP code?

<?php
for ($x = 0; $x <= 10; print ++$x)
{
    print ++$x;
}
?>
A.  

123456789101112

B.  

12345678910

C.  

1234567891011

D.  

infinite loop

5.

What will be the output of the following PHP code?

<?php
for ($x = 1; $x < 10;++$x)
{
    print "*\t";
}
?>
A.  

**********

B.  

*********

C.  

***********

D.  

infinite loop

6.

What will be the output of the following PHP code?

<?php
for ($x = 1; $x < 10;++$x)
{
    print "*\t";
}
?>
A.  

**********

B.  

*********

C.  

***********

D.  

infinite loop

7.

What will be the output of the following PHP code?

<?php
for ($x = -1; $x < 10;--$x)
{
    print $x;
}
?>


 

A.  

123456789101112

B.  

12345678910

C.  

1234567891011

D.  

infinite loop

8.

What will be the output of the following PHP code?

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

-3-4-5

B.  

-3-4

C.  

infinite loop

D.  

no output

9.

What will be the output of the following PHP code?

<?php
for ($i++; $i == 1; $i = 2)
    print "In for loop ";
print "After loop\n";
 
?>
A.  

In for loop

B.  

After for loop

C.  

In for loopAfter for loop

D.  

Infinite loop
 

10.

What will be the output of the following PHP code?

<?php
for (1; $i == 1; $i = 2)
    print "In for loop ";
print "After loop\n";
?>
A.  

In for loop

B.  

After for loop

C.  

In for loopAfter for loop

D.  

Infinite loop