Comments
Comments help explain your code and are ignored during execution. Common Pseudocode supports both single-line and multi-line comments.
Single-Line Comments
Section titled “Single-Line Comments”Single-line comments start with // and continue to the end of the line:
// This is a single-line commentx = 5 // This is an inline commentMulti-Line Comments
Section titled “Multi-Line Comments”Multi-line comments are enclosed between /* and */:
/*This is a multi-line commentthat spans multiple lines*/x = 10You can also use multi-line comments inline:
result = /* intermediate calculation */ x * yBest Practices
Section titled “Best Practices”- Use comments to explain why you’re doing something, not what you’re doing
- Keep comments up-to-date with your code
- Use single-line comments for brief explanations
- Use multi-line comments for longer descriptions or temporarily disabling code blocks
// Good: Explains the reasoning// Use binary search because the array is already sortedindex = binarySearch(sortedArray, target)
// Less helpful: Restates what the code does// Call binarySearch functionindex = binarySearch(sortedArray, target)