iterate5x <- function(x,arr = NULL) { if(x==0) { print(arr) } else { for(i in 0:5) { iterate5x(x-1,c(arr,i)) } } }