In this tutorial you will learn about the Kotlin Decision Making and its application with practical example.
Kotlin Decision Making
There are case where we want a a block of code to be executed when some condition is satisfied. In Kotlin, we have Decision Making Statement that enable computer to decide which block of code to be execute based on some conditional choices. Decision making statement statements is also referred to as selection statements.
Decision making statement evaluates single or multiple test expressions which results is “TRUE” or “FALSE”. The outcome of the test expression/condition helps to determine which block of statement(s) to executed if the condition is “TRUE” or “FALSE” otherwise.
In Kotlin, we have following types of decision making statements –
|if Statements||Block of statement executed only when specified test expression is true.|
|if else Statements||When we want to execute some block of code if a condition is true and another block of code if a condition is false, In such a case we use if….else statement.|
|if..else..if Ladder||It tests set of conditions in sequence.|
|Nested Statements||When there is an if statement inside another if statement then it is known as nested if else.|