There are many opinions on how to indent code. There is one rule that can be agreed upon. Be consistent. In order to enforce this consistency, each indentation must exactly 4 spaces.
The code for the function should begin 4 spaces from the left. For example:
int Max (int x, int y){
return (x < y) ? y : x;
}
The code for IF-ELSE should be indented as follows.
if (AVariable < MaxAmount) {
AVariable = MaxAmount - 1;
return AVariable;
} else {
return MaxAmount;
}
The indentation for loops is similar to the IF-ELSE statements. Examine the following examples.
for (int i = 0; i < MAX; ++i) {
A[i] = i;
}
while (i < MAX) {
A[i] = i;
++i;
}
do {
A[i] = i;
++i;
} while (i < MAX);
The body of a class definition should be indented:
class Cow
{
public:
Cow( ); // Default constructor
void eatHay( int amount ); // This cow eats the given amount of hay
void moo( ); // This cow moos.
private:
int age; // Age of this cow
};