title: For loop including "if" and "while" running for hours
body: <p>I have a for loop including “if” and “while” clauses written for a question. It is intended to do 1000 simulations with some conditions. I think it is not a very complicated loop, but it has been running for almost 16 hours without showing a result or prompting an error/warning (and the little red stop sign has been shown all this time),  and I can feel that my laptop has been slowed down since I started running the loop. </p>
  
  <p>So I wonder if this is something that could actually happen, or if there’s anything wrong with my code or my laptop. Any help is greatly appreciated!! </p>
  
  <p>Please see below for the code: </p>
  
  <pre><code>result.Vec &lt;- NULL
  for (trials in 1:1000) {
    sum &lt;- 0
    sum2 &lt;- 0
    n &lt;- 0
    tmp1 &lt;- sample(x=c(1, 2, 3, 4, 5, 6), size=1, replace=T, prob=c(1/6, 1/6, 1/6, 1/6, 1/6, 1/6)) 
    tmp2 &lt;- sample(x=c(1, 2, 3, 4, 5, 6), size=1, replace=T, prob=c(1/6, 1/6, 1/6, 1/6, 1/6, 1/6)) 
    sum &lt;- tmp1 + tmp2
    if (sum == 7 || sum == 11) {
      n &lt;- 1
     } else if (sum == 2 || sum == 3 || sum == 12) {
      n &lt;- 0
     } else {
       while (sum2 != sum || sum2 != 7) {
         tmp1 &lt;- sample(x=c(1, 2, 3, 4, 5, 6), size=1, replace=T, prob=c(1/6, 1/6, 1/6, 1/6, 1/6, 1/6)) 
         tmp2 &lt;- sample(x=c(1, 2, 3, 4, 5, 6), size=1, replace=T, prob=c(1/6, 1/6, 1/6, 1/6, 1/6, 1/6)) 
         sum2 &lt;- tmp1 + tmp2
         if (sum2 == sum) {
           n &lt;- 1
         } else if (sum2 == 7) {
           n &lt;- 0
         }
       }
     }
    result.Vec &lt;- c(result.Vec, n)
  }
  </code></pre>
  
  <p>Please see below for the question that my loop is for as a reference (not seeking a solution to this problem): 
  The dice game craps is played as follows. The player throws two dice, and if the sum is seven or eleven, then she wins. If the sum is two, three, or twelve, then she loses. If the sum is anything else, then she continues throwing until she either throws that number again (in which case she wins) or she throws a seven (in which case she loses). Calculate the probability that the player wins based on 1000 simulations.</p>