Index
1. Swift Coding3 min 8 sec read 2. Variables in Swift
2 min 12 sec read 3. Swift Optionals
3 min 11 sec read 4. Swift Constants
2 min 19 sec read 5. Guard in Swift
1 min 6 sec read 6. Swift if, if...else Statement
2 mins 51 sec read 7. Swift Array
6 min 2 sec read 8. Swift Dictionary
3 min 16 sec read
Swift if, if...else Statement
Sometimes in a program we need to test a condition. If that condition is true we perform first action and if the condition is false we perform second action.
Now what does that mean?
1) Simple if Statement
if statement is used to test a given condition. If given condition is satisfied then only block inside if statement will gets executed.
Example :-
import UIKit var a:Int = 10 if(a == 10) { print("a = (a)") }
Output :-
a = 10
In this swift program we first initialised a variable "a" with value "10" . Then if condition checks wether 'a == 10' or not . Since value matches block inside if is executed. That's why output 'a = 10' .
Previous Next