Swift break and continue Statements

⛔➡️ Swift break and continue Statements – Complete Beginner to Interview Guide
In Swift break and continue Statements are loop control statements used to change the normal flow of loops.
1️⃣ What is break in Swift? ⭐
Immediately stops the loop
Control moves outside the loop
2️⃣ break Example (for loop) ⭐
Output
📌 Loop stops when i == 3.
3️⃣ break Example (while loop) ⭐⭐
Output
4️⃣ What is continue in Swift? ⭐
Skips current iteration
Moves to next loop iteration
5️⃣ continue Example (for loop) ⭐
Output
📌 3 is skipped.
6️⃣ continue Example (while loop) ⭐⭐
Output
7️⃣ break and continue in Nested Loops ⭐⭐⭐
break (inner loop only)
Output
continue (inner loop only)
Output
8️⃣ Labeled break and continue ⭐⭐⭐ (Advanced)
Used to control outer loops.
Labeled break
Output
Labeled continue
Output
9️⃣ ❌ break & continue with forEach ⚠️
📌 break and continue DO NOT work in forEach.
🔟 Common Mistakes ❌
❌ Using break instead of continue
❌ Forgetting loop update in while
❌ Expecting break to exit all loops
❌ Using inside forEach
📌 Interview Questions (Swift Loop Control)
Q1. Difference between break and continue?
👉 break exits loop, continue skips iteration
Q2. How to break outer loop?
👉 Use labeled break
Q3. Can we use break in forEach?
👉 No
✅ Summary
✔ break exits loop
✔ continue skips iteration
✔ Works in for, while, repeat-while
✔ Use labels for nested loops
✔ Important for Swift logic & interviews
