In this tutorial you will learn about the Swift Nested If Else and its application with practical example.
Swift Nested If Else
In swift, when there is an if statement inside another if statement then it is known as nested if else. Nested if else can also be simplified using Swift Switch Statement.
Syntax:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
if condition1 { if condition2 { // statements } else { // statements } } else { if condition3 { // statements } else { // statements } } |
Example:-
1 2 3 4 5 6 7 8 9 10 |
let a = 25 print("W3Adda - Swift Nested If Statement") if a < 100 { if a < 50 { print("a is less than 50") } if a >= 50 { print("a is greater than 50") } } |
When we run the above swift program, will see following output –
Output:-