Return To CS 110 Home

Colour Theme   Font Size Options
 
   
   
   
Indentation and Braces

Using Indentation and Braces in Control Blocks


Video Summary: https://youtu.be/-1oDSKDjWIA


As your programs become more complex, it is important to keep code readability in mind. While good indentation won't change how your c++ code works, it will make it easier for both you and instructors that are grading or helping you to determine how your code works. Mismatched braces, on the other hand, can have significant consequences on your program.

As you write code, you should consider the following:

  1. Anything in a control block should be tabbed in one space
  2. If you have many conditions for your control statement, you should break them into multiple lines. This won't change how the code runs
  3. Writing a control statement with no braces will only include the next line. Anything after that will run normally

The following is two examples of well-formatted if statements: