mercredi 26 février 2020

With and without continue - Best approach

We've a code of which is currently using continue statement, its like this

Approach-1

boolean isEligible = false;

// code for setting isEligible

if (!isEligible)
    continue;

// 200 line code till the end of the method

So if not eligible, the the rest of the 200 line code will be omitted, but if we rewrite the code like this

Approach-2

boolean isEligible = false;

// code for setting isEligible

if (isEligible) {  
    // 200 line code till the end of the method
}

will there be any difference? We think logically its fine, will there be any issue with the performance? If both approaches are fine, can the use of continue statement be ignored by the second approach because the rest of the code that comes after it can be put inside an if block that satisfies the condition.

Aucun commentaire:

Enregistrer un commentaire