Skip to content

Instantly share code, notes, and snippets.

@josephsdavid
Created June 21, 2019 03:21
Show Gist options
  • Save josephsdavid/4d21e54fef60501584ee296f954e8d14 to your computer and use it in GitHub Desktop.
Save josephsdavid/4d21e54fef60501584ee296f954e8d14 to your computer and use it in GitHub Desktop.
99 bottles of beer in R
beersong <- function(n=99) {
if (n==1) {
cat("\n",n," bottle of beer on the wall, ",n,
" bottles of beer.\nTake one down and pass it around,",
" no more bottles of beer on the wall.\n", sep="")
cat("\nNo more bottles of beer on the wall, no more bottles of beer.\n",
"Go to the store and buy some more, 99 bottles of beer on the wall.\n", sep="")
} else {
cat("\n",n," bottles of beer on the wall, ",n,
" bottles of beer.\nTake one down and pass it around, ",
n-1, " more bottles of beer on the wall.\n", sep="")
return(beersong(n-1))
}
}
beersong()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment