This sample code works correctly, for example. comes first if, falls after the 2nd does not occur, if.
if (i < _commandList.Count)
{
if (output.Length > 0)
Console.WriteLine(output);
}
else
Console.WriteLine("Invalid Command.");
I originally encoded it like this, which does not work. It enters the first if, does not match the second, if expected, but then enters the else statement and writes.
if (i < _commandList.Count)
if (output.Length > 0)
Console.WriteLine(output);
else
Console.WriteLine("Invalid Command.");
Why doesn't the second code block work the same as the first block? Since only one line of code is below the first statement, I considered it permissible not to be {}.
For reference, the stack frame:
_commandList.Count = 1
output.Length = 0
i = 0
source
share