if statement - Software Engineering: Conditionals evaluate "good" or "bad" order -


this question has answer here:

i remember reading in software engineering book once there typical rule follow when writing if else conditional statements order of evaluation. should valid case evaluated first followed invalid/erroneous case or vice versa? there proper order cases should evaluated first?

example:

if (good) {     // exec block of code case. } else {     // bad case. } 

or

if (errorcase1) {     // errorcase1 block. } else if (errorcase2) {     // errorcase2 block. } else {     // case. } 

no fixed rule such heard usage follow this

if(usual) { (more often) } else (unusual) { (rarely occurring) } 

but if both have same function different properties better go unusual first usual can save 1 instruction.

if(x == 0)  // 1   {x = 1;}  // 2 else   {x = 2;}  // 3 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

wso2esb - How to concatenate JSON array values in WSO2 ESB? -