🚨 Off-by-one bugs in Swift loops? Check the end of the range first.
1...5 → 5 laps ✅
1..<5 → 4 laps ✅
0..<60 → 60 laps ✅ (a watch face: 60 ticks, minute 0 to 59)
🧵
🚨 Off-by-one bugs in Swift loops? Check the end of the range first. 1...5 → 5 laps ✅ 1..<5 → 4 laps ✅ 0..<60 → 60 laps ✅ (a watch face: 60 ticks, minute 0 to 59) 🧵
0 vue
Publié le 02/12/2026 06:11
1:20
🚨 Off-by-one bugs in Swift loops? Check the end of the range first.
1...5 → 5 laps ✅
1..<5 → 4 laps ✅
0..<60 → 60 laps ✅ (a watch face: 60 ticks, minute 0 to 59)
🧵
🛠️ stride(from:through:by:) includes it, like ...
⬇️ A negative step counts down
🔁 .reversed() flips a range
🎯 Build the sequence that holds exactly the values you need. Your loop body gets simpler.
www.udemy.com/course/swift...