title: Using a While for loop for a simulated coin flip in R
body: <p>I want to toss a coin and want it to stop when I get two consecutive heads in a row.</p>
  <p><strong>Here is my code</strong></p>
  <pre><code>coin&lt;-0:1
  sample(coin, size = 1, replace = TRUE)
  
  flip&lt;-function(){
    coin&lt;-0:1
    toss&lt;-sample(coin, size = 1, replace = TRUE)
  }
  flip()
  
  heads=1
  tosses&lt;-c()
  while (heads==&quot;?&quot;) {
    tosses=c(tosses, flip())
  }
  </code></pre>
  <p><strong>I have my flip function made. I am not sure if I need use a if else statement or count the flips to check for back to back 1's after each coin flip? I am using a while for loop</strong></p>