menu

Kotlin Conditional Statements


1. What is the syntax for the when statement?

when (expression) { case value -> statements }

when (expression) { case value -> statements; default -> statements }

when (expression) { value -> statements }

when (expression) { value -> statements; default -> statements }


2. What is the purpose of the "unless" expression in Kotlin?

To check multiple conditions.

To execute a block of code if a condition is true.

To execute a block of code if a condition is false.

None of the above.


3. What is the syntax for the if-else statement?

if (condition) { } else { }

if (condition) { } else

if { } else { }

if (condition) { }


4. Which conditional statement is used to check for a single condition?

if

else

switch

none of the above


5. What is the syntax for the if-let statement?

if (variable != null) { } else { }

if (variable) { } else { }

if (variable == null) { } else { }

if (variable?.let { } ) { } else { }


6. What is the purpose of the "else" statement?

To check multiple conditions.

To execute a block of code if the "if" condition is true.

To execute a block of code if the "if" condition is false.

None of the above.


7. What is the syntax for the if-else if statement?

if (condition) { } else if (condition) { } else { }

if (condition) { } else { } if (condition) { }

if (condition) { } if (condition) { } else { }

if { } else if { } else { }


8. What is the purpose of the "when" expression in Kotlin?

To check multiple conditions.

To return a value based on a condition.

To execute a block of code if a condition is true.

None of the above.


9. Which of the following is an example of a when statement?

if (condition) { } else { }

when (expression) { case value -> statements }

switch (expression) { case value: statements; default: statements; }

None of the above.


10. Which of the following is true about the "when" statement in Kotlin?

It is used to check multiple conditions.

It is similar to the switch statement in Java.

It can be used as a replacement for if-else and switch statements.

All of the above.