[prev] 44 [next]

Conditionals (cont)

Indentation is very important in promoting the readability of the code

Each logical block of code is indented:

// Style 1    
if (x)
{
   statements;
}

               

// Style 2 (preferred)
if (x) {
   statements;
}

               

// Preferred else-if style
if (expression1) {
   statements1;
} else if (exp2) {
   statements2;
} else if (exp3) {
   statements3;
} else {
   statements4;
}