Indentation Tools
Manually indenting code is a tedious task. A good code editor can automatically indent code as it is being written.
There also exists tools to reformat code after it has been written. One useful Linux utility is the indent program. Run the program with the ——k—and—r—style flag to get something similar to the "Student" style. Instead use the ——original flag for the "Bell Labs" style.
Indentation Styles
Choose one of the two styles and use it consistently:
Student Style | Bell Labs Style |
---|---|
if (condition) { statement(s) } |
if (condition) { statement(s) } |
if (condition) { statement(s) } else if (condition) { statement(s) } else { statement(s) } |
if (condition) { statement(s) } else if (condition) { statement(s) } else { statement(s) } |
for (loop control expressions) { statement(s) } |
for (loop control expressions) { statement(s) } |
while (condition) { statement(s) } |
while (condition) { statement(s) } |
do { statement(s) } while (condition); |
do { statement(s) } while (condition); |
switch (expression) { case value1: statement(s) case value2: statement(s) default: statement(s) } |
switch (expression) { case value1: statement(s) case value2: statement(s) default: statement(s) } |