for-in مع نطاق
for i in 1...5 {
print(i)
}
for i in stride(from: 0, to: 10, by: 2) {
print(i) // 0,2,4,6,8
}
المرور على مجموعة
let fruits = ["تفاح", "موز", "برتقال"]
for fruit in fruits {
print(fruit)
}
for (index, fruit) in fruits.enumerated() {
print("\(index): \(fruit)")
}
تجاهل المتغيّر
for _ in 1...3 {
print("تكرار")
}
while و repeat-while
var n = 3
while n > 0 {
print(n)
n -= 1
}
repeat {
print("مرّة على الأقل")
} while false
🎯 التالي: النصوص.