Skip to content

Instantly share code, notes, and snippets.

@hadley
Last active September 10, 2015 16:49
Show Gist options
  • Save hadley/00b9a5832dae99ed1234 to your computer and use it in GitHub Desktop.
Save hadley/00b9a5832dae99ed1234 to your computer and use it in GitHub Desktop.
bottles_of_beer <- function(i = 99) {
message("There are ", i, " bottles of beer on the wall, ", i, " bottles of beer.")
while(i > 0) {
tryCatch(
Sys.sleep(1),
interrupt = function(err) {
i <<- i - 1
if (i > 0) {
message(
"Take one down, pass it around, ", i,
" bottle", if (i > 1) "s", " of beer on the wall."
)
}
}
)
}
message("No more bottles of beer on the wall, no more bottles of beer.")
}
bottles_of_beer()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment