I have this snippet of code that is giving me problems.
The last break statements gives an error of “unreachable code detected”
this has caused a logical flaw in my program.
can someone identify the problem please?
thanks!
case 127232:
case1 = splited[0];
changeRow[inServer] = "Audit Privileges and Logs:\n";
changeRow[inServer + " Exception"] = "No Exception";
writeToFile(Directory.GetCurrentDirectory() + @"\" + inServer + "127232.txt", case1);
if (case1.Contains("audit level;failure") || case1.Contains("audit level;all"))
{
Console.WriteLine("success!");
changeRow[inServer + "Observations"] = changeRow[inServer + "Observations"] + "1) Audit options found .";
changeRow[inServer] = changeRow[inServer] + "string pattern audit level;failure or auditlevel;all found";
break;
}
else
{
//Audit Privileges should have been in enabled for sys and system accounts or the security administrator.
changeRow[inServer + "Observations"] = changeRow[inServer + "Observations"] + "1) No audit options found.";
changeRow[inServer] = changeRow[inServer] + "Correct audit options not configured!";
changeRow[inServer + " Exception"] = "Exception";
break;
}
break;
You have a
breakin both yourifand yourelseclause, meaning that thebreakat the bottom will never be reached.It doesn’t really matter in this particular case but it seems the compiler is not “smart” enough to figure that out. That’s not necessarily a bad attitude for the compiler to take since this could be considered sloppy coding practice.
Just get rid of both
breakstatements within theifandelseclauses or, alternatively, refactor to:What you have in your original is not really that much different to something like:
which I always think is cleaner as:
I don’t like being tabbed to death by code unless it’s absolutely necessary 🙂