Comments in Kotlin

Most programming languages support comments, and Kotlin is no exception. If you are looking to improve readability of your source code then use comments. There are two types of comments supported by Kotlin which are explained below-

  1. Single-Line Comment
  2. Block Comment

Single-Line Comment

It is also known as end-of-line comment or line comment. It starts with // and goes till the end of a line.

Syntax

//I am an end-of-line comment 

Example

val tax = "GST" //This variable will store the name of tax

Block Comment

This type of comment spans multiple lines. It starts with /* and ends with */.

Syntax

/*
I
am
a
block
comment 
*/

Example

/*
This program will
print numbers
from 1 to 10. 
*/
public fun main(args: Array<String>) {
   var i = 1
   while(i<=10){
      println(i);
      i++
   }
}

Output

1
2
3
4
5
6
7
8
9
10