I’m having trouble with this piece:
if (a)
{
if (b) // when this check fails, I need to go v
doSomething(); // v
} // v
else // < here
doSomethingElse();
How do I do that?
UPD: if statements are nested because a checks if an object is not null, preventing exception caused by immediately checking for a null-object’s parameter.
The only way to do it short of employing
gotowhere available is to guard theelsebranch of the outerifstatement with a separate condition, rather than making it anelsebranch.Assuming that there are calculations preceding the nested
ifthat prevent you from performing both checks at once, you could do this:However, if the code in your conditions literally consists of calling functions
doSomethinganddoSomethingElse, there is no harm in duplicating the invocation of thedoSomethingElsefunction inside the nestedelsebranch.