Hello, I am trying to set up a function that will give me a sum of something, but it didn't work out and the output seemed not what I want.

I am conjecturing that it is because I used another function to set up the main function. I know it is possible that once I get to a `return`

or `print`

then everything else behind won't be executed. But I don't know how to avoid the necessary `return`

since it is used to construct my function.

```
prob.a<-function(N){
for(j in 1:9){
k <- rep(1:N, times=N)
i <- rep(1:N, each=N)
n <- i <= k
count <- rep(0,9) #initiate counter
alpha <- function(p) {
for(d in 1:p) {
m=first_digit(d)
count[m]=count[m]+1 #counting
}
print(count[j]) #the result of counting
}
result<-sum(alpha(length(i[n]))/(k[n]*N)) #desirous result of prob.a function
return(result)
}
}
```

And I try this function by giving N=3:

```
> prob.a(3)
[1] 1
[1] 1
```

The result shows that the loop is not working, does anyone know what causes that? Thanks a lot.