1.

Amongst multiple elseif and nested if, which would take less runtime?(a) multiple elseif(b) nested if(c) elseif(d) elseif & nested ifThe question was posed to me in class test.This key question is from Branching in chapter MATLAB Programming of MATLAB

Answer»

Correct choice is (a) multiple elseif

The best 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.



Discussion

No Comment Found

Related InterviewSolutions