Skip to main content
ProductsDesktop toolsTASTECADDrawing reviewTASTEFILESFile managementTASTEFTPFile transferTASTESSHRemote workspaceTASTEZIPCompression and extractionTASTEWINMFile managementDeveloper toolsTASTECODERust integrated development environmentTASTESTUDIOIntegrated development and test environmentTASTEETLData integration (ETL)ServersTASTEREMOTERemote desktop serverTASTEGEOGeospatial serverTASTEMAILMail workspaceInvestingTASTESTOCKStock auto-trading desktop appGet startedDownloadsDocumentationBuyAll products
Marketplace
News
TechNewsToday's dev newsDeveloper docsProgramming languagesRustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartWeb front-end frameworksNext.jsReactVue.js · NuxtSvelteKitAngularServer frameworksSpring BootDjangoFastAPIASP.NET CoreNestJS · ExpressApp & desktop frameworksTauriFlutterReact NativeElectronAlgorithmsAlgorithm basicsCore algorithmsAdvanced algorithmsPractical algorithms
CommunityProjectsDevelopment logsPromptsAI tool issuesShowcaseCommunity guide
Work with usTech transferWebsite buildDesktop app buildRelease and payment pipelineSales partnerContact
ServicesRemote desktopCustom installer packages
TASTEDEV
Products

Desktop tools

TASTECADComplex drawings, opened with easeTASTEFILESJust the files you need, as fast as possibleTASTEFTPThe tidiest path for your filesTASTESSHA stronger link between you and your serversTASTEZIPPack faster, unpack saferTASTEWINMA keyboard-first file manager with two panes

Developer tools

TASTECODEEdit, build, debug and test Rust apps in one windowTASTESTUDIOFrom editing to remote tests and approved AI fixesTASTEETLMove data while you watch the values

Servers

TASTEREMOTEA remote desktop you run on your own serverTASTEGEORebuilding a GeoServer-compatible geospatial server in RustTASTEMAILTake back control of your email

Investing

TASTESTOCKStock auto-trading that follows the rules you set: when, and what

Get started

DownloadsLatest builds of every productDocsHow to use each productBuySubscriptions and perpetual licencesAll productsEvery product at a glance
All products
MarketplaceNews
Tech

News

Today's dev newsOfficial announcements on languages, frameworks, GitHub and AIDeveloper docsGuides to languages, frameworks and algorithms

Programming languages

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

Frameworks

Web front-end frameworksNext.jsReactVue.js · NuxtSvelteKitAngular
Server frameworksSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
App & desktop frameworksTauriFlutterReact NativeElectron

Algorithms

Algorithm basicsComplexity analysis · Sorting · Searching · Basic data structures · Trees and heapsCore algorithmsGraph traversal · Shortest paths & minimum spanning trees · Dynamic programming · Greedy algorithms · Divide and conquer · BacktrackingAdvanced algorithmsString algorithms · Math and number theory · Bit manipulation · Segment trees · Union-findPractical algorithmsCoding interview strategy · LRU cache · Rate limiting · Consistent hashing
All development docs
Community
ProjectsDiscover builders and their workDevelopment logsDecisions and lessons learnedPromptsReusable instructionsAI tool issuesProblems and workarounds for Claude, Codex, GeminiShowcaseFinished resultsCommunity guideHow we build in the open
Work with us
Tech transferNative apps in Rust and eguiWebsite build10 languages, accounts, docs and downloadsDesktop app buildRust and egui, no WebViewRelease and payment pipelineSigning, MSI, deb, rpm, AppImage, hashesSales partnerRecommend us and earn 30%ContactBuilds, partnerships and investment
Services
Remote desktopReach your computer from a browserCustom installer packagesOnly the features you need, settings preloaded
Buy
EN
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
Log in
Log in
TASTEDEV

From small tools to better development.

support@tastedev.netSupport TASTEDEV
ProductsProduct lineupBuyDocsDownloadsMarketplaceSupport
CommunityProjectsDevelopment logsPromptsAI tool issuesShowcase
PoliciesAbout usPrivacy policyTerms of serviceSubscription termsRefund policyCommunity guidelines
AccountLog inSign up
Visitors
Today
Yesterday
Total views
Company
GXSOFT
Representative
CHOI YOUNG GU
Business registration number
853-44-00368
Address
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
Phone
+82-10-4404-1523
Email
whitecalvin@tastedev.net
Privacy officer
CHOI YOUNG GU

© 2026 TASTEDEVProduct information is based on verified development sources.Released · improving

Kotlin docs
Kotlin
Getting StartedSyntax BasicsTypes and DataModules and PackagesErrors and TestingKey Concepts
Discussions

Kotlin guide · 2/6

Syntax Basics

This chapter covers the syntax you will use every day: variables, functions, conditionals, loops, and string templates. With these in hand you can already write useful small programs.

Variables: val and var

val declares a read-only variable that cannot be reassigned; var declares one that can. Idiomatic Kotlin reaches for val first and uses var only when a value really has to change. Types are usually inferred, so you can leave them out.

const val MAX_USERS = 100    // compile-time constant, top level or inside an object

fun main() {
    val language = "Kotlin"  // inferred as String
    var count: Int = 0       // or spell out the type
    count += 1
    // language = "Java"     // error: val cannot be reassigned
    println("$language $count / $MAX_USERS")
}

Note that val fixes the reference, not the object. With val list = mutableListOf(1), calling list.add(2) is perfectly legal.

Functions

Functions start with fun; parameter and return types follow a colon. When the body is a single expression, replace the braces with = and let the compiler infer the return type.

fun add(a: Int, b: Int): Int {
    return a + b
}

fun square(x: Int) = x * x   // expression body, returns Int

fun greet(name: String, greeting: String = "Hello", mark: Char = '!'): String =
    "$greeting, $name$mark"

fun main() {
    println(add(2, 3))                      // 5
    println(square(4))                      // 16
    println(greet("Sam"))                   // Hello, Sam!
    println(greet("Ana", greeting = "Hi"))  // Hi, Ana!
    println(greet(mark = '?', name = "Lee")) // Hello, Lee?
}

Parameters with default values can be skipped, and named arguments let you pass only what you need in any order. That removes most of the overload boilerplate common in Java. A function that returns nothing useful has the return type Unit, which you normally omit.

if and when are expressions

if produces a value, which is why Kotlin has no ternary operator: you assign the result of if directly.

fun describe(score: Int): String {
    val passed = if (score >= 60) "pass" else "fail"

    val grade = when {
        score >= 90 -> "A"
        score >= 80 -> "B"
        score >= 70 -> "C"
        else -> "F"
    }
    return "$passed ($grade)"
}

fun kind(x: Any): String = when (x) {
    0, 1 -> "zero or one"
    in 2..9 -> "a single digit"
    is String -> "a string of length ${x.length}"
    else -> "something else"
}

when replaces Java's switch. Given a subject, branches can match values, ranges (in) or types (is). Without a subject it behaves like an if-else chain, testing conditions top to bottom. Used as an expression it must cover every case, so you usually need an else branch. Being able to call x.length inside the is String branch is a smart cast, explained in chapter 6.

String templates

Embed values with $name or arbitrary expressions with ${...}. Raw strings use triple quotes, and trimIndent() strips the common leading indentation.

fun main() {
    val user = "Ana"
    val items = listOf("apple", "pear")
    println("$user has ${items.size} items in the cart")
    println("Total: ${items.size * 3} dollars")

    val json = """
        {
          "name": "$user",
          "count": ${items.size}
        }
    """.trimIndent()
    println(json)
}

Ranges and loops

There is no C-style for (i = 0; i < n; i++). Instead, for ... in iterates over ranges and collections.

ExpressionMeaningValues
1..5closed range1, 2, 3, 4, 5
0..<5end excluded, same as 0 until 50, 1, 2, 3, 4
10 downTo 0 step 3counting down by 310, 7, 4, 1
'a'..'e'character rangea, b, c, d, e
fun main() {
    for (i in 1..5) print("$i ")
    println()
    for (i in 10 downTo 0 step 3) print("$i ")
    println()

    val fruits = listOf("apple", "pear", "grape")
    for ((index, fruit) in fruits.withIndex()) {
        println("$index: $fruit")
    }

    var n = 3
    while (n > 0) {
        println("$n left")
        n--
    }

    repeat(2) { println("round $it") }

    outer@ for (x in 1..3) {
        for (y in 1..3) {
            if (x * y == 4) break@outer   // leaves both loops
            println("$x x $y")
        }
    }
}

Ranges also work in membership checks such as if (age in 20..29). To break out of an outer loop, label it (outer@) and use break@outer.

Summary

  • Prefer val; use var only for values that must change.
  • Functions support default and named arguments, and single-expression bodies use =.
  • if and when are expressions; when can match values, ranges and types.
  • Build strings with $name and ${expression} templates.
  • Loop with for ... in over ranges like 1..5, 0..<n, downTo and step, or over collections.
Questions about this chapter?
Previous chapterGetting StartedNext chapterTypes and Data

0 comments

Top commentsNewest first

Sign in · Sign in to leave a comment.