Comments
- Comments can be used to explain kotlin code.
- Comments can be used to make code more readable.
- Comments are ignored by kotlin Compiler
- It can also to be used to prevent execution whem testing alternaive code.
Single-Line Comments
- Single line comments start with two forword slashes (//)
- Code between two forward slashes will ignored by kotlin compiler.
Example
//this is comment
println("hello world")
Multi-Line Comments
- Multi-line comments start with /* and ends with */
- Code between /* and */ will ignored by kotlin compiler.
Example
/* this is
multi line
comment
*/
println("Hello world")
Following example shows if you want to prevent specific line to execute you can use comments thier.
Example
println("First")
//println("Second")
println("Third")
//println("Fourth")
//println("Sixth")
println("Seventh")
//println("Eighth")
println("Ninth")
println("Tenth")
Above example only prinln "First Third Seventh Ninth Tenth" because other line are become code they does not executes.
Comments
Post a Comment