dimanche 24 novembre 2019

Efficiency of if statements vs. if-else statements

Is it computationally efficient to have multiple if statements instead of if-else statements.

For example,

if (logical statement)    % if statement #1
    (expressions to execute) 
end 

if (logical statement)    % if statement #2
    (expressions to execute) 
end 

if (logical statement)    % if statement #3
    (expressions to execute)  
end

compared to

if (logical statement)
    (expressions to execute) 
elseif (logical statement)
    (expressions to execute)
else 
    (expressions to execute)
end

Can it lead to less coding errors on the longer run and is it better for code management? What are the other advantages or disadvantages of following this method?

Aucun commentaire:

Enregistrer un commentaire