All days
Day 01Module 1 · Kotlin Basics· 3–5 hrs

Kotlin Basics I — Variables, Operators, Control Flow

Start with pure Kotlin (no Android yet). You'll declare variables, use arithmetic and comparison operators, and control flow with if/when/loops. This is the syntax you'll use in every later day.

0% done

Key concepts

  • val vs var (immutable vs mutable)
  • Type inference and explicit types
  • Arithmetic and comparison operators
  • if as an expression
  • when expression and ranges
  • for, while, do-while loops

Lectures in this day

  1. 01

    Course Overview

    Here is what you will do in 12 days. First 2 days: learn the Kotlin language (the words we write). Next 2 days: learn how to build with classes (little machines). Next 2 days: make your first real Android screens. After that: connect screens, save data on the phone, then finish with a full app that uses Firebase (a free cloud database).

    Real life · Think of it like a 12-day sports camp. On Day 1 you just warm up. By Day 12 you can play a full match.

    Practice · 3 quick questions

    1. Q1.How many days is this roadmap?

    2. Q2.What do the first two days focus on?

    3. Q3.What is Firebase used for in Day 11+?

    Pick one answer per question.
  2. 02

    Declaring Variables (Part 1)

    A variable is a labeled box that holds a value. Kotlin has two kinds. `val` is a box you fill once and never change (like your date of birth). `var` is a box you can refill any time (like today's score in a game).

    Real life · `val` is your birthday — written once, never changes. `var` is the money in your wallet — it goes up and down all day.
    kotlin
    val id: String = "NID-1990-42"   0
    var balance = 1500                1
    balance += 500                    2
    println("Hi $id, balance = $balance")

    Practice · 3 quick questions

    1. Q1.Which keyword makes a value you cannot change again?

    2. Q2.Which one CAN be reassigned later?

    3. Q3.What does `balance += 500` do?

    Pick one answer per question.
  3. 03

    Declaring Variables (Part 2)

    Sometimes a box is allowed to be empty. We show that with a `?` after the type (like `String?`). We can also glue values into text using `$name` inside quotes — that's called a string template. `const val` is a value that never changes AND is known before the app runs.

    Real life · A middle-name box on a form can be empty — some people don't have one. Kotlin makes you say 'this box might be empty' with `?`.
    kotlin
    const val APP_NAME = "TourBook"     0
    val middleName: String? = null      1
    
    2
    val label = "${APP_NAME} user: ${middleName ?: "—"}"
    println(label)   3

    Practice · 3 quick questions

    1. Q1.What does `String?` mean?

    2. Q2.Inside "Hi $name", what is `$name`?

    3. Q3.What is `const val` best for?

    Pick one answer per question.
  4. 04

    Arithmetic Operators

    Kotlin does math like a calculator: `+` add, `-` subtract, `*` multiply, `/` divide, `%` remainder (what's left over). One trick: if you divide two whole numbers, the answer is a whole number (the decimal is thrown away). To keep the decimal, make one side a decimal (`3.0` instead of `3`).

    Real life · You have 1000 taka and 3 friends. `1000 / 3` gives 333 (whole taka each). `1000.0 / 3` gives 333.33 (with paisa).
    kotlin
    val total = 1000
    val each = total / 3          0
    val eachExact = total / 3.0   1
    val leftover = total % 3      2
    println("$each each, $leftover left over, exact=$eachExact")

    Practice · 3 quick questions

    1. Q1.What is `10 % 3`?

    2. Q2.What is `7 / 2` in Kotlin (both Int)?

    3. Q3.How do you keep the decimals?

    Pick one answer per question.
  5. 05

    If Statement

    `if` lets your program pick between paths: if a rule is true do this, otherwise do that. In Kotlin, `if` also gives back a value, so you can save its result into a variable.

    Real life · A traffic light. Red → stop. Yellow → slow. Green → go. Same idea: check, then act.
    kotlin
    fun fare(distanceKm: Int): Int =
        if (distanceKm <= 2) 40                       0
        else if (distanceKm <= 10) 40 + (distanceKm - 2) * 15
        else 40 + 8 * 15 + (distanceKm - 10) * 12
    
    println(fare(6))   1

    Practice · 3 quick questions

    1. Q1.What does `if` do?

    2. Q2.Can `if` return a value in Kotlin?

    3. Q3.Which comparison is 'less than or equal'?

    Pick one answer per question.
  6. 06

    Range and When Statement

    `when` is a cleaner way to check many cases at once — like a big list of 'if this, do that'. `1..10` is a range meaning 'every whole number from 1 to 10'. `in` asks 'is this value inside that range?'.

    Real life · Report card grades: 80–100 = A, 70–79 = B, and so on. You look at the score and pick the band.
    kotlin
    0
    fun grade(score: Int): String = when (score) {
        in 80..100 -> "A"   1
        in 70..79  -> "B"
        in 60..69  -> "C"
        in 50..59  -> "D"
        else       -> "F"   2
    }
    
    println(grade(72))   3
    println(grade(45))   4

    Practice · 3 quick questions

    1. Q1.What does `1..10` mean?

    2. Q2.`x in 1..5` is true when…

    3. Q3.Why use `when` instead of many `if/else`?

    Pick one answer per question.
  7. 07

    Loops in Kotlin

    A loop repeats the same steps many times. `for` walks through a range or a list. `while` keeps going as long as a rule is true. `downTo` counts backwards. `step 2` skips every other number.

    Real life · An elevator that goes floor by floor: `1..10` goes up. `10 downTo 1` comes down. `step 2` visits only even floors.
    kotlin
    for (i in 1..5) print("$i ")             0
    println()
    for (i in 10 downTo 2 step 2) print("$i ") 1
    println()
    
    var n = 3
    while (n > 0) {                          2
        println("tick $n")
        n--                                  3
    }

    Practice · 3 quick questions

    1. Q1.How many times does `repeat(3) { ... }` run the block?

    2. Q2.`for (i in 1..3)` prints i as…

    3. Q3.What does `while (x < 5)` do?

    Pick one answer per question.

Real-life analogies

val vs var

val is like your birth date — set once, never changes. var is like your phone battery — always changing.

when

Ordering at a restaurant: 'if it's breakfast → eggs, if lunch → sandwich, else → chef's special'. `when` is the menu.

Ranges

1..10 is like the floor buttons in an elevator: a fixed span you can iterate through in order.

Code examples

Variables & inference

kotlin
val name: String = "Rakib"   0
var age = 24                   1
age += 1
println("Hello $name, you are $age")

when as an expression

kotlin
fun grade(score: Int): String = when (score) {
    in 80..100 -> "A"
    in 70..79  -> "B"
    in 60..69  -> "C"
    in 50..59  -> "D"
    else        -> "F"
}

println(grade(84)) 0

when is exhaustive when used as an expression — the else branch is required.

Loops

kotlin
for (i in 1..5) print("$i ")           0
for (i in 10 downTo 1 step 2) print("$i ") 1

var n = 3
while (n > 0) { println(n); n-- }

Hands-on checklist

Milestone

You can write basic Kotlin syntax without looking it up.

Common pitfalls

  • Forgetting else in a when used as an expression — compile error.
  • Using == vs === (structural vs referential equality) — always use == for value comparison.