Comments are used to explain code or to prevent execution. Kotlin supports both single-line and multi-line comments. Letβs look at them interactively!
This type is great for short notes or disabling a specific line.
fun main() { val name = "Kotlin" // Storing language name println(name) // Print the value }
Perfect for explaining blocks of code or temporarily disabling chunks during testing.
fun main() { /* This block initializes a greeting message, and then prints it to the console */ val message = "Hello from Kotlin!" println(message) }
*/
or your entire program may be commented out by accident!
Unlike Java, Kotlin supports nesting of multi-line comments. This helps when debugging larger sections.
fun main() { /* Outer comment starts println("This line is commented") /* Inner nested comment */ val x = 10 */ println("Only this will print!") }
val name = "John" // Assign "John" to name β (not useful!)
val discount = price * 0.1 // 10% discount for returning users
Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!