How to count backwards (Print the numbers N, N - 1, ..., 0 (included)) in Swift

1 Answer

0 votes
import Foundation

let n = 5

for i in stride(from: n, through: 0, by: -1) {
    print("\(i) ", terminator: "")
}



/*
run:

5 4 3 2 1 0 

*/

 



answered Jul 20, 2025 by avibootz
...