menu

Kotlin Conditional Statements


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


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 unless expression?

unless (condition) { }

if (condition) { } else { }

unless { } else { }

unless (condition) { } else { }


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

if

else

switch

none of the above


5. Which of the following is an example of an if-let statement?

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

if (variable) { } else { }

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

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


6. Which conditional statement is used to check multiple conditions?

if

else

switch

none of the above


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


8. What is the syntax for the switch statement?

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

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

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

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


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


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