Control Structures(loop In Php)(Php ) Questions and Answers
Question 1. What will be the output of the following PHP code?
how are u
hi
error
no output
Explanation:-
Answer: Option A. -> how are u Uninitialized x is set to 0, thus if condition fails.
Question 2. What will be the output of the following PHP code ?
hi
no output
error
how are u
Explanation:-
Answer: Option D. -> how are u x is incremented after if which evaluates to false.
Question 3. What will be the output of the following PHP code ?
how are uhello
hihello
hi
no output
Explanation:-
Answer: Option B. -> hihello else condition without brackets performs the following statements only.
Question 4. What will be the output of the following PHP code ?
true
false
error
no output
Explanation:-
Answer: Option D. -> no output The nested for loop is not entered if outer condition is false.
Question 5. What will be the output of the following PHP code ?
true
false
error
no output
Explanation:-
Answer: Option A. -> true Due to post increment and post decrement only the first condition is satisfied.
Question 6. What will be the output of the following PHP code ?
hihihi
hihellohihellohihello
hellohellohello
hi
Explanation:-
Answer: Option D. -> hi When break is encountered it leaves the loop.
Question 7. What will be the output of the following PHP code ?
hihihi
hihellohihellohihello
hellohellohello
hi
Explanation:-
Answer: Option A. -> hihihi When continue is encountered it skips to the next iteration
Question 8. What will be the output of the following PHP code ?
0
infinite loop
-1
1
Explanation:-
Answer: Option C. -> -1 The order of execution is initialization, check, increment/decrement, check, increment/decrement, check, increment/decrement….so on .
Question 9. What will be the output of the following PHP code ?
24
134
1234
1
Explanation:-
Answer: Option A. -> 24 The order of execution is initialization, check, increment/decrement, check, increment/decrement, check, increment/decrement….so on.
Question 10. What will be the output of the following PHP code ?
10
infinite loop
no output
error
Explanation:-
Answer: Option B. -> infinite loop There is no check condition to stop the execution of the loop.