Kotlin Comments

Kotlin Comments

Comments are used to explain Kotlin code and make it more readable. The compiler completely ignores comments, meaning they will not be executed. They are strictly for developers to leave notes!

Kotlin supports two types of comments: single-line and multi-line.


1. Single-line Comments

Single-line comments start with two forward slashes //. Any text between // and the end of the line is ignored by Kotlin.

Example

fun main() {
  // This is a single-line comment
  println("Hello World") // This comment is at the end of a line
}

2. Multi-line Comments

Multi-line comments start with /* and end with */. Any text between these markers is ignored. This is highly useful for writing long explanations or temporarily disabling blocks of code during testing.

Example

/* The code below will print the words Hello World
to the screen, and it is amazing */
println("Hello World")