Swift If Statement
The if statement is a control flow statement which is used when we want to perform different actions according to some specified conditions which are either true or false.
Here, expression is a Boolean expression which returns either true or false.
Example: (if condition is true)
This is a positive number. This will be executed anyways.
In the above program, constant number is initialized with a value 5. Here, test expression evaluates true so inside the body of if statement is executed.
Example: (if condition is false)
If we initialise the value with negative number like -5 and the test condition is same then the test expression will evaluate false. So, the statement inside the code block of if is skipped without execution.
This will be executed anyways.
In the above example, you can see that the statement inside the code block of if is not executed.