menu

Kotlin Conditional Statements


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


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


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

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

if (variable) { } else { }

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

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


4. Which of the following is true about the "if-let" statement in Kotlin?

It is used to check if a variable is null.

It can be used as a replacement for the if-else statement.

It can be nested within other conditional statements.

All of the above.


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


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


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

if

else

switch

none of the above


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


9. What is the syntax for the unless expression?

unless (condition) { }

if (condition) { } else { }

unless { } else { }

unless (condition) { } else { }


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

if

else

switch

none of the above