Kotlin Training Program

DOWNLOAD APP

FEEDBACK

Comments

“Any fool can write code that a computer can understand. Good programmers write code that humans can understand.”

by Martin Fowler

Comments are plain text that we can write in our programs to explain code, give examples etc. If we write such plain text anywhere in the program, it won’t compile :

 fun main() {
		This program prints "Hello Comments" // ERROR! Not allowed
		println("Hello Comments")
}
 

The above code won’t run because line # 2 is a plain text written directly.

To help the compiler know which is code and which is comment (plain text), we use the following syntax :

Single line comments //

 // Write your comment here...
 

Multiline comments /* */

 /*
Write your comment here...
 */
 

Comments are ignored by the compiler. They are written to improve the readability of the program. This is important because while working in a team, comments help explain code to other teammates and increase efficiency. Also, programmer may need to read the code after few weeks, months or even years. In that case also, comments are very useful to get the context.