Key Concepts

Review core concepts you need to learn to master this subject

If Expressions

var morning = true if (morning) { println("Rise and shine!") } // Prints: Rise and shine!

An if expression is a conditional that runs a block of code when its condition has a true value.

Conditional Expressions
Lesson 1 of 1
  1. 1
    When we go on adventures, sometimes the road is straightforward and other times, the road splits and we must choose a path to take. Conditionals are like forks in the road: they determine the direc…
  2. 2
    An if expression is a conditional that executes a body of code only when a specified Boolean value returns true. Assume we had a Boolean variable called raining: var raining = true We can use an …
  3. 3
    Often accompanying the if expression is another conditional called the else expression. The else expression executes a block of instructions when the condition in the if expression has a false valu…
  4. 4
    To create more complex conditions for our conditionals to evaluate, we can use comparison operators. Comparison operators evaluate the relationship between two values in order to return an expres…
  5. 5
    Another way to compare two values is with the equality operators. We can use the equality operator (==) to check if the value on the right side of the operator is equal to the value on the left….
  6. 6
    An else-if expression can be used to add a plethora of more conditionals for our program to evaluate. Let’s say we created a Kotlin program that determines what we will wear depending on the tempe…
  7. 7
    Logical operators evaluate the relationship between two or more Boolean expressions and return a true or false value. There are several operators that we can use: &&, ||, and !. The logical AND op…
  8. 8
    We can combine expressions containing logical operators to create even more complex Boolean expressions. When combining logical operators, the order of evaluation is as follows: 1. Boolean express…
  9. 9
    Similar to the concept of a “dream inside of a dream” from the movie Inception, a conditional can exist inside of another conditional. This occurrence is …
  10. 10
    Another expression that controls the flow of execution in a program is the when expression. A when expression is made up of multiple branches that contain values, or arguments, to check for. If …
  11. 11
    In Kotlin, range provides a powerful tool that represents a consecutive succession of values that can often be used in conjunction with conditionals. In Kotlin, ranges are created using the .. op…
  12. 12
    Great job getting to the end of this lesson. Let’s review the content we learned: * Conditional expressions control the flow of execution in a program. * An if expression executes a block of code …

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo