title: New to R and need to count the amount of time I have run the while loop
body: <p>The below function I suppose to simulate $n$ $N (0,1)$ random variates using the Accept-Reject algorithm with a Cauchy candidate. I hope it is correct.</p>
  <pre><code>ar.normal&lt;-function(n){
  x&lt;-double(n) 
  i&lt;-1
  while(i&lt;(n+1)){  # this is to make sure we continue until we fill our x vector
  C&lt;-rcauchy(1) 
  u&lt;-runif(1)
  temp&lt;-(M^(-1))*(1/sqrt(2*pi))*exp(-C^2/2)/(1/(pi*(1+C^2)))
  if(u&lt;-temp){
    x[i]&lt;-C
    i&lt;-i+1
  }
  }
  return(list(x,i))
  }
  </code></pre>
  <p>I need to know how many times I have gone to my while function in order to get 1000 draws that worked in my condition which is u&lt;-temp. and it stored in x vector. I do not know how I can count that.</p>