Amongst multiple elseif and nested if, which would take less runtime?

Amongst multiple elseif and nested if, which would take less runtime?
A. multiple elseif
B. nested if
C. elseif
D. elseif & nested if
 
Answer: a
Explanation: If multiple elseif and nested if has the same number of conditions. Multiple elseif checks at each step if it at all it has to go to the next condition. But nested if checks each condition before leaving the entire control structure. Hence, the number of steps covered in multiple elseif is less than nested if. Thus the former will take less time.
 

Tìm kiếm

Back
Top