Concept Flow - Comments and documentation syntax
Start of code
Check line
Is comment?
Ignore
Next line
End
The program reads each line, ignores comments, attaches documentation to code, and executes code lines.
/** * This function prints a greeting */ fun greet() { // This is a comment println("Hello") }
| Step | Line Content | Type Detected | Action | Output/Effect |
|---|---|---|---|---|
| 1 | /** | Doc comment start | Start doc comment block | Begin doc capture |
| 2 | * This function prints a greeting | Doc comment line | Add to doc comment | Doc content stored |
| 3 | */ | Doc comment end | End doc comment block | Attach doc to function greet |
| 4 | fun greet() { | Code | Execute function start | Function greet defined |
| 5 | // This is a comment | Single-line comment | Ignore line | No effect |
| 6 | println("Hello") | Code | Execute print statement | Prints: Hello |
| 7 | } | Code | Execute function end | Function greet ends |
| 8 | End of code | Stop execution | Program ends |
| Variable | Start | After Step 1 | After Step 3 | Final |
|---|---|---|---|---|
| docComment | empty | started | attached to greet | attached to greet |
| output | empty | empty | empty | Hello printed |
Kotlin comments: // single-line comment ignored by compiler /* multi-line comment ignored */ /** documentation comment attached to code * used by tools */ Comments do not affect program output but help explain code.
// to start a single-line comment.//, which is correct. /* This is a single-line comment */ is for multi-line comments. <!-- This is a single-line comment --> is HTML style. # This is a single-line comment is used in some scripting languages but not Kotlin./* ... */ to write multi-line comments./* ... */. // This is a multi-line comment is single-line comment syntax. /** This is a multi-line comment */ is documentation comment syntax. <!-- This is a multi-line comment --> is HTML comment syntax.fun main() {
// println("Hello")
println("World")
}// println("Hello") is a comment, so it does not run.println("World") runs, so output is "World".fun main() {
/* This is a comment
println("Hello")
}/* but does not have a closing */.*/, the compiler treats the rest as comment, causing syntax error./** ... */ for documentation comments that tools can parse.Pass the test and this pattern moves unknown