Connect 4 Techs
  • Home
  • Excel
  • Data Analysis
  • Finance
  • MBA
    • Marketing
  • Kotlin
  • Gadgets
    • Apple
    • Samsung
    • Canon
    • Tech News
  • About
  • Contact
No Result
View All Result
Connect 4 Techs
  • Home
  • Excel
  • Data Analysis
  • Finance
  • MBA
    • Marketing
  • Kotlin
  • Gadgets
    • Apple
    • Samsung
    • Canon
    • Tech News
  • About
  • Contact
No Result
View All Result
Connect 4 Techs
No Result
View All Result
Home Kotlin

Kotlin Booleans & Kotlin If … Else (Lesson 7 PDF)

Ahmed Elhozayen by Ahmed Elhozayen
October 11, 2026
in Kotlin
0
Kotlin Booleans & Kotlin If … Else (Lesson 7 PDF)

Kotlin is a statically typed programming language that runs on the Java Virtual Machine (JVM). It was developed by JetBrains and is now an official language for Android development. Kotlin is designed to be concise, expressive, and safe. It is also interoperable with Java, which means that you can use Kotlin and Java code together in the same project.

Kotlin

You might also like

Kotlin Class Functions & Inheritance (Lesson 13 PDF)

Kotlin Classes and Objects & Constructors (Lesson 12 PDF)

Kotlin Functions & Classes (Lesson 11 PDF)

Overview about the Lesson

This lesson is part of a series of lessons on Kotlin programming. In this lesson, we will cover the use of Booleans and If … Else statements in Kotlin. We will start by discussing what Booleans are and how they work. We will then explore the different types of Booleans in Kotlin, including nullable Booleans. Finally, we will look at some examples of how to use Booleans and If … Else statements in Kotlin.

The Content Of The Lesson

The content of this lesson is divided into the following sections:

  1. What are Booleans?
  2. Nullable Booleans
  3. If … Else statements
  4. Examples

Why This Lesson

This lesson is important because Booleans and If … Else statements are essential parts of any programming language. They allow us to make decisions based on conditions, which is essential for building complex applications. By understanding Booleans and If … Else statements in Kotlin, you will be able to write more efficient and effective code.

Booleans and if…else in Kotlin: Examples

The PDF explains Booleans and conditional logic. Here are the patterns you will use most, with their output.

Boolean values and expressions

fun main() {
    val isLoggedIn = true
    val age = 17
    val isAdult = age >= 18
    println(isLoggedIn)   // true
    println(isAdult)      // false
}

A Boolean is either true or false. Comparisons such as age >= 18 produce Booleans.

if, else if, else

fun main() {
    val temperature = 31
    if (temperature > 35) {
        println("Very hot")
    } else if (temperature > 25) {
        println("Warm")
    } else {
        println("Cool")
    }
}
// Output: Warm

Conditions are checked from top to bottom, and only the first matching branch runs.

if as an expression

In Kotlin, if returns a value, so it replaces Java’s ternary operator (? :), which Kotlin does not have:

fun main() {
    val score = 72
    val result = if (score >= 50) "Pass" else "Fail"
    println(result)   // Pass

    val max = if (10 > 7) 10 else 7
    println(max)      // 10
}

When if is used as an expression, the else branch is required.

Combining conditions

fun main() {
    val hasTicket = true
    val age = 15
    if (hasTicket && age >= 12) println("Welcome in")
    if (!hasTicket || age < 12) println("Sorry, no entry")
}
// Output: Welcome in

Common mistakes

  • Using = (assignment) instead of == (comparison). Kotlin reports an error, which saves you from a classic bug.
  • Comparing Booleans to true: write if (isAdult), not if (isAdult == true).
  • Long else-if chains: when you have many branches, the when expression in Lesson 8 is clearer.

Practice exercise

Print “Even” or “Odd” for a number using if as an expression.

fun main() {
    val n = 7
    val type = if (n % 2 == 0) "Even" else "Odd"
    println("$n is $type")   // 7 is Odd
}

Frequently Asked Questions

Does Kotlin have a ternary operator?

No. Use if (condition) a else b, which is an expression and does the same job.

Can an if block return a value from several lines?

Yes. The value of the last expression in the block is returned: val x = if (ok) { log(); 1 } else { 0 }.

Continue the course

← Previous: Lesson 6: Set Operations & Grouping  |  Next: Lesson 8: When, While, Break & Continue →

  1. Lesson 1: Getting Started
  2. Lesson 2: Syntax & Output
  3. Lesson 3: Comments & Variables
  4. Lesson 4: Data Types
  5. Lesson 5: Operators
  6. Lesson 6: Set Operations & Grouping
  7. Lesson 7: Booleans & If…Else (you are here)
  8. Lesson 8: When, While, Break & Continue
  9. Lesson 9: Arrays
  10. Lesson 10: For Loops & Ranges
  11. Lesson 11: Functions & Classes
  12. Lesson 12: Classes, Objects & Constructors
  13. Lesson 13: Class Functions & Inheritance

Conclusion

In conclusion, Booleans and If … Else statements are essential parts of any programming language. In this lesson, we covered the different types of Booleans in Kotlin, including nullable Booleans. We also looked at some examples of how to use Booleans and If … Else statements in Kotlin. By understanding Booleans and If … Else statements in Kotlin, you will be able to write more efficient and effective code.

Download From Link

You can download the lesson from the following link:

From Here

Tags: AndroidJavaJVMKotlinProgrammingtechnology
Previous Post

Kotlin Set Operations & Grouping (Lesson 6 PDF)

Next Post

Kotlin When & While Loop, Break & Continue (Lesson 8 PDF)

Ahmed Elhozayen

Ahmed Elhozayen

Related Posts

Kotlin Class Functions & Inheritance (Lesson 13 PDF)
Kotlin

Kotlin Class Functions & Inheritance (Lesson 13 PDF)

by Ahmed Elhozayen
October 11, 2026
Kotlin Classes and Objects & Constructors (Lesson 12 PDF)
Kotlin

Kotlin Classes and Objects & Constructors (Lesson 12 PDF)

by Ahmed Elhozayen
October 11, 2026
Kotlin Functions & Classes (Lesson 11 PDF)
Kotlin

Kotlin Functions & Classes (Lesson 11 PDF)

by Ahmed Elhozayen
October 11, 2026
Kotlin For Loop & Kotlin Ranges (Lesson 10 PDF)
Kotlin

Kotlin For Loop & Kotlin Ranges (Lesson 10 PDF)

by Ahmed Elhozayen
October 11, 2026
 Kotlin Arrays (Lesson 9 PDF)
Kotlin

 Kotlin Arrays (Lesson 9 PDF)

by Ahmed Elhozayen
October 11, 2026
Next Post
Kotlin When & While Loop, Break & Continue (Lesson 8 PDF)

Kotlin When & While Loop, Break & Continue (Lesson 8 PDF)

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recommended

The Ultimate Excel Handbook PDF

The Ultimate Excel Handbook PDF

October 11, 2026
How-to-Make-an-Old-Phone-Faster-3

How to Record Phone Calls on an iPhone

April 7, 2024

Categories

  • apple
  • Canon
  • Data Analysis
  • Excel
  • Finance
  • ios
  • Kotlin
  • Marketing
  • MBA
  • Samsung
  • Software Tutorials
  • Technology

Don't miss it

20 Essential Excel Formulas Every Data Analyst Must Know in 2026
Data Analysis

20 Essential Excel Formulas Every Data Analyst Must Know in 2026

May 18, 2026
Excel guide for data analytics learners
Excel

Excel for Data Analysis PDF

October 11, 2026
The Ultimate Guide to Financial Modeling PDF
Excel

The Ultimate Guide to Financial Modeling PDF

October 11, 2026
The Ultimate Excel Handbook PDF
Excel

The Ultimate Excel Handbook PDF

October 11, 2026
𝟓𝟎 𝐄𝐱𝐜𝐞𝐥 𝐒𝐡𝐨𝐫𝐭𝐜𝐮𝐭 𝐊𝐞𝐲
Excel

50 Excel Shortcut Key PDF: Streamline Your Workflow

March 21, 2025
Most Useful Excel Keyboard Shortcuts For Windows and Mac OS
Excel

Most Useful Excel Keyboard Shortcuts for Windows and Mac OS PDF

March 21, 2025
Connect4Techs Tech

Practical, free guides on Excel, data analysis, finance, business and programming — written to help you learn faster and work smarter.

Follow on Facebook

Topics

  • Excel
  • Kotlin
  • MBA
  • Finance
  • Data Analysis
  • Apple
  • Technology
  • Software Tutorials

Latest articles

  • 20 Essential Excel Formulas Every Data Analyst Must Know in 2026May 18, 2026
  • Excel for Data Analysis PDFAug 31, 2025
  • The Ultimate Guide to Financial Modeling PDFApr 19, 2025

Company

  • About us
  • Contact
  • Privacy Policy
  • Terms of Use
  • IT Certification PDFs
© 2026 Connect4Techs. All rights reserved. Privacy · Terms · Contact
No Result
View All Result
  • Home
  • Excel
  • Data Analysis
  • Finance
  • MBA
    • Marketing
  • Kotlin
  • Gadgets
    • Apple
    • Samsung
    • Canon
    • Tech News
  • About
  • Contact