Kotlin Syntax

Kotlin File Structure

Kotlin programs are made of functions and classes, typically starting with a main function as the entry point.

fun main() {
    println("Hello, Kotlin!")
}

Semicolons

Kotlin does not require semicolons at the end of statements, though they can be used.

val x = 10  // valid
val y = 20;   // also valid but not needed

Comments

Kotlin supports both single-line and multi-line comments:

// This is a single-line comment

/* This is
   a multi-line comment */

Print Statements

Kotlin provides two functions for displaying output: print() and println().

  • print() outputs text without moving to a new line.
  • println() outputs text and then appends a newline character, moving the cursor to the next line AFTER.

Example:

Loading...
Output:

Indentation and Blocks

Kotlin uses braces {} for code blocks, and indentation is recommended for clarity, though not syntactically required.

Need Help?

Ask the AI if you need help understanding or want to dive deeper in any topic