Comments
Published Dec 15, 2022
Contribute to Docs
Comments are pieces of text within a Kotlin program that are ignored by the compiler. They can be text, symbols, or valid code meant to provide additional information to aid in understanding the program. Comments are good for a variety of reasons like explaining a code block or indicating some hints.
Single-line Comments
In Kotlin, single-line comments are created with two consecutive forward slashes //
:
// Prints text in ("...")println("The line above is a single line comment");
A single-line comment can also be used inline to comment after a line of code:
println("This is a single line comment") // Prints text in ("...")
Multi-line Comments
Multi-line comments are created by surrounding the lines with /*
at the beginning and */
at the end:
/*The text in ("...")would be only code to be executed*/println("The line above is a multi-line comment");
Example
The code in the following that is commented out will not execute when the program is run:
// Calculate sum of valuesvar operation = 100 + 50println(operation)// Output: 150
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.