Last active
September 10, 2015 16:49
-
-
Save hadley/00b9a5832dae99ed1234 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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