Last active
July 30, 2019 00:20
-
-
Save pravj/e4af092f494bd46cddc9 to your computer and use it in GitHub Desktop.
99 Bottles of Beer in Swift Language
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var i = 99 | |
while i > 0 | |
println(i + " bottles of beer on the wall, " + i + "bottles of beer.") | |
var num = i - 1 | |
if i == 1 { | |
var num = "no more" | |
} | |
println("Take one down and pass it around, " + num + "bottles of beer on the wall.") | |
println("No more bottles of beer on the wall, no more bottles of beer.") | |
println("Go to the store and buy some more, 99 bottles of beer on the wall.") |
Swift 5:
for i in (1...99).reversed() {
print("\(i) bottles of beer on the wall, \(i) bottles of beer.")
var num = String(i - 1)
if ( i == 1 ) { num = "no" }
print("Take one down and pass it around, \(num) bottles of beer on the wall.")
}
print("No more bottles of beer on the wall, no more bottles of beer.")
print("Go to the store and buy some more, 99 bottles of beer on the wall.")
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try this instead.
for i in reverse(1...99) {
println("(i) bottles of beer on the wall, (i) bottles of beer.")
var num = toString(i - 1)
if ( i == 1 ) { num = "no" }
println("Take one down and pass it around, (num) bottles of beer on the wall.")
}
println("No more bottles of beer on the wall, no more bottles of beer.")
println("Go to the store and buy some more, 99 bottles of beer on the wall.")