Swift Decision Making

In this tutorial you will learn about the Swift Decision Making and its application with practical example.

Swift Decision Making Statements

There are case where we want a a block of code to be executed when some condition is satisfied. In Swift, we have rich set of 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 Swift, we have following decision making statements –

Swift Decision Making Statements
Statement Description
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 Statements When we want to add multiple condition checks in single if else statement then by using swift if else-if else statement we can easily add multiple conditions.In if else-if else statement we have a option to add alternative else if statements but we are limited to have only one if and else block in statement.
Nested If Statements When there is an if statement inside another if statement then it is known as nested if else.
Switch Statement A switch statement evaluates an expression against multiple cases in order to identify the block of code to be executed.

In this tutorial we have learn about the Swift Decision Making and its application with practical example. I hope you will like this tutorial.