I have to follow the coding standards at my company, and they've got one which I disagree with, but which I must follow anyway.

The standard is: 'If' statements which are followed by only one line of code: Don't use the curly braces. Yes, I know this is bad practice, and I know why, but the company has standardized on it and my code reviews get corrections if I don't do it their way.

My question is what happens with nested if-else-if statements in situations like that. I tried googling on this, but the discussions I've found only ever talk about the basic case, and the philosophical reasons why this is a bad practice. I have yet to see an example that addresses this one particular case:

Original, with braces, to show desired code execution flow:
Code:
// Report whether MSI uninstall was successful or not, based on the exit code of MSI;
// if we're not reporting errors, then don't say it's an error if the exit code is nonzero
if (0 == installResult)
{
    Console.WriteLine("MSI Uninstalled.");
}
else
{
    if (reportErrors)
    {
        Console.WriteLine("Error: Uninstallation failed. MSI Error code: {0}", installResult);
    }
    else
    {
        Console.WriteLine("MSI Exit Code: {0}", installResult);
    }
}


With braces removed, to meet coding standards:
Code:
// Report whether MSI uninstall was successful or not, based on the exit code of MSI;
// if we're not reporting errors, then don't say it's an error if the exit code is nonzero
if (0 == installResult)
    Console.WriteLine("MSI Uninstalled.");
else
    if (reportErrors)
        Console.WriteLine("Error: Uninstallation failed. MSI Error code: {0}", installResult);
    else
        Console.WriteLine("MSI Exit Code: {0}", installResult);



Will the second example function exactly like the first example? My concern is the last ELSE statement. When I google this, every discussion says things like "it goes up to the first semicolon it finds" and stuff like that, so it makes me wonder if that last ELSE is handled as expected.

I'm pretty sure it will be handled correctly as expected. The syntax checker and compiler like it. Just wondering if anyone knows for sure.

It probably would have taken me less time to just write a separate test program than to write this post on the BBS. Oh well....
_________________________
Tony Fabris