Comments are notes you add to your code to explain what it does. They're completely ignored by the computer when your program runs – they exist only for humans reading the code.
In iPseudo, comments start with the #
symbol:
# This is a comment
Everything after #
on that line is a comment and will be ignored.
Algorithm CommentExample
# This is a full-line comment
var age = 25 # This is an inline comment
Print "Hello" # Comments can appear after code
Endalgorithm
Explain what the code does:
# Calculate the area of a circle
var area = 3.14159 * radius * radius
Explain why the code does something:
# Using 0.08 because state tax rate is 8%
var taxRate = 0.08
Mark things to do later:
# TODO: Add input validation
var age = Input "Enter age:"
Divide code into logical sections:
# ===== GET USER INPUT =====
var name = Input "Name:"
var age = Input "Age:"
# ===== PROCESS DATA =====
var isAdult = age >= 18
# ===== DISPLAY RESULTS =====
Print name, "is an adult:", isAdult
# Add 1 to x
x = x + 1
# Print the result
Print result
# Increment attempt counter for retry logic
x = x + 1
# Display final calculated value to user
Print result
Consider who will read your code:
Good variable names reduce the need for comments:
# t is total price
var t = 100
# r is tax rate
var r = 0.08
# Calculate final amount
var f = t + (t * r)
var totalPrice = 100
var taxRate = 0.08
var finalAmount = totalPrice + (totalPrice * taxRate)
Start your programs with a documentation header:
Algorithm StudentGradeCalculator
# =============================================
# Program: Student Grade Calculator
# Author: Your Name
# Date: October 5, 2025
# Description: Calculates final grade from
# test scores and homework grades
# =============================================
# Program code starts here...
Endalgorithm
Algorithm TemperatureConverter
# =============================================
# Temperature Converter (Celsius to Fahrenheit)
# Converts temperature using: F = C × 9/5 + 32
# =============================================
# Get temperature input from user
Print "=== Temperature Converter ==="
var celsius = Input "Enter temperature in Celsius:"
# Convert to Fahrenheit using standard formula
# Formula: F = C × 9/5 + 32
var fahrenheit = celsius * 9 / 5 + 32
# Display both temperatures for comparison
Print ""
Print "Temperature Conversion:"
Print celsius, "°C =", fahrenheit, "°F"
# Provide context for common temperatures
Print ""
Print "Reference: Water freezes at 0°C (32°F)"
Print "Reference: Water boils at 100°C (212°F)"
Endalgorithm
# Bad: This is obvious
x = 5 # Set x to 5
# Bad: This is a hack, needs fixing
result = value * 1.0000001 # Don't ask why
Too many comments make code harder to read:
# Bad: Over-commented
var x = 5 # declare x
var y = 10 # declare y
var sum = x + y # add them
Print sum # print result
Good code is self-explanatory for the "how". Use comments to explain:
Use different comment styles for different purposes:
# ===== MAJOR SECTION =====
# Subsection description
var x = 5 # Inline note about this line
Algorithm FinalGradeCalculator
# =============================================
# Final Grade Calculator
# Calculates weighted average from assignments
# Weights: Tests 50%, Homework 30%, Final 20%
# =============================================
Print "=== Grade Calculator ==="
Print ""
# ===== GET SCORES =====
# Get individual component scores from user
var testAverage = Input "Enter test average (0-100):"
var homeworkAverage = Input "Enter homework average (0-100):"
var finalExam = Input "Enter final exam score (0-100):"
# ===== CALCULATE WEIGHTED GRADE =====
# Using school's official weighting policy:
# - Tests contribute 50% of final grade
# - Homework contributes 30% of final grade
# - Final exam contributes 20% of final grade
var testWeight = 0.50
var homeworkWeight = 0.30
var finalWeight = 0.20
# Calculate weighted components
var testContribution = testAverage * testWeight
var homeworkContribution = homeworkAverage * homeworkWeight
var finalContribution = finalExam * finalWeight
# Sum all weighted components for final grade
var finalGrade = testContribution + homeworkContribution + finalContribution
# ===== DISPLAY RESULTS =====
Print ""
Print "=== GRADE BREAKDOWN ==="
Print "Tests (50%):", testAverage
Print "Homework (30%):", homeworkAverage
Print "Final Exam (20%):", finalExam
Print "------------------------"
Print "FINAL GRADE:", finalGrade
# Provide letter grade interpretation
Print ""
Print "Grade Scale: A(90+), B(80-89), C(70-79), D(60-69), F(<60)"
Endalgorithm
Comment Type | When to Use | Example |
---|---|---|
Explanatory | Explain what code does | # Calculate total price |
Clarification | Explain why you did something | # Using 8% based on state law |
TODO | Mark future improvements | # TODO: Add error handling |
Section Header | Divide code into sections | # ===== CALCULATIONS ===== |
#
and are ignored by the program