Recall & Review
beginner
What is the difference between an expression and a statement in Kotlin?
An expression produces a value and can be used wherever a value is expected. A statement performs an action but does not produce a value.
Click to reveal answer
beginner
Why does Kotlin prefer expressions over statements?
Because expressions return values, Kotlin code can be more concise, flexible, and easier to read and maintain.
Click to reveal answer
intermediate
How does using expressions improve code readability?
Expressions allow combining actions and values in one line, reducing boilerplate and making the code flow clearer.
Click to reveal answer
beginner
Give an example of an expression in Kotlin.
An example is the if expression: val max = if (a > b) a else b. It returns a value instead of just controlling flow.
Click to reveal answer
intermediate
What advantage does using expressions provide in functional programming style?
Expressions enable chaining and composing functions easily, supporting immutability and side-effect-free code.
Click to reveal answer
In Kotlin, which of the following is an expression?
✗ Incorrect
The if expression returns a value assigned to result. The others are statements without return values.
Why are expressions preferred over statements in Kotlin?
✗ Incorrect
Expressions produce values and can be combined, making code concise and flexible.
Which Kotlin construct is an expression rather than a statement?
✗ Incorrect
The if-else in Kotlin returns a value, so it is an expression.
What is a benefit of using expressions in Kotlin?
✗ Incorrect
Expressions let you write concise code by combining actions and values.
Which statement about Kotlin expressions is true?
✗ Incorrect
By definition, expressions produce a value.
Explain why Kotlin favors expressions over statements and how this affects code style.
Think about how expressions can be used inside other expressions or assigned to variables.
You got /4 concepts.
Describe an example where using an expression instead of a statement improves Kotlin code.
Consider how if can return a value directly.
You got /4 concepts.