Comments are notes that you write in your code to explain what it does. They are ignored by the swazi interpreter when running your program - they exist only for humans to read.
Use // to write a comment that lasts until the end of the line.
swazi
// This is a single line commentdata jina = "John Doe" // You can also put comments after code// chapisha("This line won't run because it's commented out")chapisha("This will run!") // But this comment won't affect the code
For longer comments that span multiple lines, use /* to start and */ to end.
swazi
/*This is a multi-line comment.You can write as many lines as you want.Everything between the opening and closing symbolswill be ignored by SwaziLang.*/data jumla = 10 + 20/*The code below calculates the sumand prints the result to the screen*/chapisha(jumla)
SwaziLang also allows string literals to act as comments when they're not assigned to anything.
Single line string comment:
swazi
"This is a comment using a string literal"data umri = 42
Multi-line string comment (Pythonic style):
swazi
"""This is a multi-line comment using string literals.Just like Python's docstrings!You can write multiple lines here."""data jina = "John"'''You can also use single quotesfor multi-line string comments'''chapisha jina
This style is especially useful if you're familiar with Python and want to write documentation in a similar way.
// C-style single line comment# Python-style single line comment/*C-style multi-line comment*/"String literal comment""""Python-stylemulti-line string comment"""'''Alternative Python-stylemulti-line string comment'''
// Calculate total price including taxdata bei = 100data kodi = bei * 0.16 // 16% tax ratedata jumla = bei + kodi"""Function to greet a userThis will be explained more in the functions section"""
// Bad: stating the obviousdata x = 5 // set x to 5data y = 10 // set y to 10data jumla = x + y // add x and y// Good: explaining why or what the purpose is// Calculate discount for returning customersdata punguzo = bei * 0.10
"""Program: Simple CalculatorAuthor: Your NameDate: 2025Description: Calculates the sum of two numbers"""// Input valuesdata a = 15data b = 25// Perform calculationdata matokeo = a + b # Store the result// Display outputchapisha("Jibu ni:")chapisha(matokeo)
data jina = "Hassan"// chapisha("Debug: checking name value")// chapisha(jina)chapisha("Habari, " + jina + "!")/*TODO: Add age verificationkama umri < 18 { chapisha("You are a minor")}*/
data radius = 7data pi = 3.14159data area = pi * radius * radiuschapisha(area)
Solution:
swazi
// Calculate the area of a circledata radius = 7 # Circle radius in centimetersdata pi = 3.14159 # Mathematical constant"""Formula: Area = π × r²This calculates the area of a circlegiven its radius"""data area = pi * radius * radiuschapisha(area) // Output the result
Comments in SwaziLang
What are Comments?
Comments are notes that you write in your code to explain what it does. They are ignored by the swazi interpreter when running your program - they exist only for humans to read.
Comments are essential for:
Types of Comments in SwaziLang
SwaziLang supports 4 different ways to write comments, giving you flexibility in how you document your code.
1. Single Line Comments with
//Use
//to write a comment that lasts until the end of the line.Output:
2. Single Line Comments with
#You can also use
#for single line comments (Python style).3. Multi-Line Comments with
/* */For longer comments that span multiple lines, use
/*to start and*/to end.Note: Multi-line comments are great for:
4. String Literal Comments
SwaziLang also allows string literals to act as comments when they're not assigned to anything.
Single line string comment:
Multi-line string comment (Pythonic style):
This style is especially useful if you're familiar with Python and want to write documentation in a similar way.
Comparison of All Comment Styles
When to Use Each Style
//#/* */"..."or"""..."""Best Practices
✅ Good Comments
❌ Avoid Over-Commenting
Practical Examples
Example 1: Documenting a Program
Example 2: Debugging with Comments
Example 3: Mixed Comment Styles
Key Points to Remember
//,#,/* */, and string literalsPractice Exercise
Try adding comments to this code:
Solution:
What's Next?
Now that you know how to document your code with comments, you're ready to learn about:
Remember: Good comments make your code easier to understand, maintain, and share with others!