PHP Loop MCQs

This section focuses on "Loop" in PHP. These Multiple Choice Questions (mcq) should be practiced to improve the PHP skills required for various interviews (campus interview, walk-in interview, company interview), placements, entrance exams and other competitive examinations.

1. PHP supports ____ types of looping techniques?

A. 2
B. 3
C. 4
D. 5

View Answer


2. How many main parameter are used in for loop?

A. 2
B. 3
C. 4
D. 1

View Answer


3.  do-while loop is an _____ control loop ?

A. exit
B. exist
C. easy
D. entry

View Answer


4. while loop is an _____ control loop ?

A. exit
B. exist
C. easy
D. entry

View Answer


5. foreach loop is used to iterate over ____?

A. number
B. object
C. function
D. array

View Answer


6. Which loop evaluates the condition expression as Boolean, if it is true, it executes the statements and when it is false it will terminate?

A. For loop
B. while loop
C. do-while loop
D. All of the above

View Answer


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

<?php  
  
for ($num = 1; $num <= 10; $num += 2) { 
    echo "$num "; 
}  
  
?>

A. 1 3 5 7 9
B. 1 2 3 4 5
C. 9 7 5 3 1
D. Error

View Answer


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

<?php  
$num = 20; 
  
while ($num < 12) { 
    $num += 2; 
    echo $num, "\n"; 
} 
?>

A. Error
B. No Output
C. infinite loop
D. Only one garbage value

View Answer


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

<?php   
$num = 2; 
do { 
    $num += 2; 
    echo $num, "\n"; 
} while ($num < 0); 
?>

A. Error
B. No Output
C. infinite loop
D. 4

View Answer


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

<?php   
  $arr = array (10, 20, 30); 
    foreach ($arr as $val) {  
        echo "$val1 \n"; 
    }  
?>

A. 10 20 30
B. No Output
C. 10
D. undefined variable

View Answer





Also check :


Discussion


* You must be logged in to add comment.