Comments
Also known as: comment comments doc docstring documentation note
● Beginner3 minSpec 1.2
Comments are notes for people: the compiler skips them.
Three kinds
// …runs to the end of the line./* … */can run over several lines, or sit inside a line./// …is a doc comment: it describes the declaration below it, and editors show it on hover.
// A line comment runs to the end of the line.
/* A block comment can run
over several lines. */
/// A doc comment describes what follows: editors show it on hover.
fn total(price: Int, items: Int) -> Int {
price * items /* inside a line too */
}
fn main() {
/* Code put aside, comments and all:
print(total(1, 2)) /* an old note */
*/
print(total(30, 4))
}The program ran and printed:
kavach run comments.kav
120A comment says why the code is as it is. What the code does, the code itself should say.
Try it yourself
Put a whole
print line aside without deleting it, so it doesn't run.Show the answer
Wrap it in /* … */, or start the line with //.
What Kavach does for you
Comments nest
/* … */may hold other block comments, so code that has comments can be put aside whole.