Nested ifs:
if (condition) { // half-massive amount of code here if (!breakOutCondition) { //half-massive amount of code here } }
At the risk of being slowed down - it happened to me in the past - I mentioned that the other (unpopular) option, of course, would be the scary goto ; the expression about the break is simply disguised.
And finally, I will repeat the general opinion that your design can probably be improved so that the mass if statement is not necessary, not to mention its exit from it. At the very least, you should be able to extract several methods and use return:
if (condition) { ExtractedMethod1(); if (breakOutCondition) return; ExtractedMethod2(); }
phoog Dec 15 '11 at 16:44 2011-12-15 16:44
source share