Indentation Style



next up previous
Next: General Guidelines Up: No Title Previous: Commenting

Indentation Style

The most important thing to remember about your indentation style is to be consistent. Use the same style throughout a program and use identical indentation for similar C++ constructs.

There is no one correct indentation style. Here are two popular formats we suggest.

Style 1:

while (expression) {
   ...
   ...
}

Style 2:

while (expression)
{
   ...
   ...
}

The ``...'' represents where the code to be executed gets placed. Note that both styles can be used with all of the other C++ constructs like for, if, do and while in a similar manner.

In general, use tab stops of two to four characters. This leads to clearly identifiable indentations and does not run your code off the page too fast. You may wish to use an Electric-C package in your text editor to help indent your code as you are entering it. This package will also help check for mismatched parenthesis or braces. See your editor's documentation for further information.



Kan Deng
Fri Jan 20 18:19:52 EST 1995