Home

hersto:  Source Code Indentation / Switch Statements

 

Rant to the author:

    

Check for a response

Please read Source Code Indentation for the basic idea first.

Although switch statements in C/C++ rely on the break statement, the break statement does not really influence the controll flow because they just denote the default controll flow of leaving the switch statement at the end of a case block. It is more the omission of the break statement that influences control flow, which is nowadays considered bad programming style anyway.

Therefore it is enough to indent the case statement so that it shows the relation ship with the enclosing switch statement. Also indenting the break statement would bring too much visual clutter to the code and decrease readability.

An Example:

 0:
 1:  switch(Value)
 2:  {
 3:  case 1:
 4:      DoSomething();
 5:      break;
 6:
 7:  case 2:
 8:      DoSomethingElse();
 9:      X+= 3;
10:      Z= 5;
11:      break;
12:
13:  default:
14:      DoNothing();
15:      Z|= 3;
16:      break;
17:  }
18:

 

__.-.__
end of document