No - the condition will be checked once and then the entire block executed. Another option might be to inject bailouts in the block:
if (condition)
{
DoSomething();
if(!condition) return;
DoSomethingElse();
if(!condition) return;
DoAnotherThing();
}
Another way is if the functions could be parameterized so that you could put them in a loop:
foreach (varmyParam in parameters)
{
if(condition)
DoSomething(myParam);
}
Edit
After thinking a bit more this may be your best option:
List<Action> funcs = new List<Action> {DoSomething, DoSomethingElse, DoAnotherThing};
foreach( Action a in funcs)
{
if(condition) a();
}
That requires that all of the methods have the same signature (in your case return void
with no parameters) but it's a bit cleaner.