Commenting Control Structures

Commenting Control Structures

Control structures - conditional statements and loops - change control flow of code. Given that extra complexity, it is worth making sure that all control structures receive some kind of commenting.

For many shorter control structures, you can typically have comments summarizing the end result of the entire control structure.

For longer control structures or more complicated cases, it may be appropriate to instead have:

  • Comments before the control structure summarizing the conditions being checked.

  • Additional comments in the body of the control structure providing information on what happens in response to a given condition.

The tips below demonstrate how these principles can be carried out in different scenarios:

 

Say goodbye to blindsided code updates ad.png