"jjj"
Swift Conditionals
Swift Conditionals – Make Smart Choices
Conditionals help your code decide what to do based on certain situations.
if Statement
Checks a rule. If it's true, runs the block.
let age = 20
if age >= 18 {
print("You're an adult")
}
Executes the code block solely when the rule is satisfied.
else Statement
Used when the if condition is false.
if age >= 18 {
print("Adult")
} else {
print("Minor")
}
else if Chain
Used for multiple checks.
let score = 85
if score >= 90 {
print("Grade A")
} else if score >= 80 {
print("Grade B")
} else {
print("Try Again")
}
switch Statement
Simpler way to match values.
let day = "Monday"
switch day {
case "Monday":
print("Start fresh!")
case "Friday":
print("Weekend is close!")
default:
print("Just another day")
}
Summary
Conditionals let your app react differently in different situations. Swift supports if, else, else if, and switch for flexible decision-making.
Prefer Learning by Watching?
Watch these YouTube tutorials to understand GIT Tutorial visually:
What You'll Learn:
- 📌 Swift for Beginners Part 8 - If Else Conditionals
- 📌 Introduction to SWIFT - 03 Conditional Statements