Use single-line comments, also called inline comments, to provide brief summary comments for chunks of code.
Proceed single-line comments with a blank line and align the comment with the code it summarizes. Do not feel the need to comment every single line of code, rather summarize chunks of code between 3 to 7 lines in length.
Begin single-line comments with a double slash (//) that tells the compiler to ignore the rest of the line. Note: do not place any characters between the two slashes.
By separating chunks of code by blank lines and proceeding each chuck with an explanatory comments, readers (and yourself) can quickly identify and understand sections of code where specific actions are being performed.
Always add comments while you are coding rather than waiting until the program is finished. The summaries and reasons will be fresh and accurate rather than place-fillers that offer no real value.
// Compute the exam average score for the midterm exam sumOfScores = 0; for (int i = 0; i < scores.length; i++) sumOfScores = sumOfScores + scores[i]; average = float(sumOfScores) / scores.length;