menu

Kotlin Conditional Statements


1. 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.


2. Which of the following is an example of an if-else if statement?

if (condition) { } else { }

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

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

None of the above.


3. 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 { }


4. Which of the following is an example of an if-else statement?

if (condition) { } else { }

if (condition) { }

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

None of the above.


5. What is the syntax for the unless expression?

unless (condition) { }

if (condition) { } else { }

unless { } else { }

unless (condition) { } else { }


6. 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.


7. Which of the following is an example of a switch statement?

if (condition) { } else { }

if (condition) { }

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

None of the above.


8. Which of the following is true about the "if-else if" statement in Kotlin?

It is used to check multiple conditions.

It can be used as a replacement for the switch statement.

It can be nested within other conditional statements.

All of the above.


9. What is the purpose of the "default" case in a switch statement?

To check for a specific condition.

To execute a block of code if none of the cases match.

To execute a block of code if the switch expression is null.

None of the above.


10. 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 }