This section focuses on “Loop” in PHP. These Multiple Choice Questions:

1. PHP supports ____ types of looping techniques?

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

Ans : C

Explanation: PHP supports four types of looping techniques.

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

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

Ans : B

Explanation: There are three main parameters to the code, namely the initialization, the test condition and the counter.

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

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

Ans : A

Explanation: The do-while loop is an exit control loop which means that it first enters the loop, executes the statements, and then checks the condition

4. while loop is an _____ control loop ?

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

Ans : A

Explanation: The do-while loop is an exit control loop which means that it first enters the loop, executes the statements, and then checks the condition.

5. foreach loop is used to iterate over ____?

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

Ans : D

Explanation: for each loop: This loop is used to iterate over the array. For every counter of the loop, an array element is assigned and the next counter is shifted to the next element.

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

Ans : B

Explanation: While loop evaluates the condition expression as Boolean, if it is true, it executes the statements and when it is false it will terminate.

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

Ans : A

Explanation: the output of the following PHP code 1 3 5 7 9

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

Ans : B

Explanation: The output of the following PHP code is no output

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

Ans : D

Explanation: 4 is the output of the following code because a statement is executed at least once on using the do-while loop..

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

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

Ans : D

Explanation: undefined variable $var1 will be the output of the following PHP code…

thank you……….

Leave a Reply

Your email address will not be published. Required fields are marked *