title: How to have two conditions in a While loop?
body: <p>Basically I have two while loops in my code. All they do is count in increments of 1 from 0 to either 10 or -10. The vectors that count are "count1" and "count2". This is happening in my code in two separate while loops. However, I now need each count dependent on each other so I need them within the same loop. Is it possible to have the two separate while conditions working in one loop.
  For example, what I have now is:</p>
  
  <pre><code>  count1 = 0
    count2 = 0
    l_RWM = vector()
    r_RWM = vector()      
  
  
  while (count1 &lt; 10 &amp;&amp; count1 &gt; -10){
  
    count1 = count1 + (sample(c(1,-1), 1, prob = c(.55,.45)))
  
    l_RWM = append(l_RWM,count1)
  
  }
  
  while (count2 &lt; 10 &amp;&amp; count2 &gt; -10){
  
    count2 = count2 + (sample(c(1,-1), 1, prob = c(.55,.45)))
  
    r_RWM = append(r_RWM,count2)
  
  }
  </code></pre>
  
  <p>But I want something like</p>
  
  <pre><code>while (count1&amp;count2 &lt; 10 &amp;&amp; count1&amp;count2 &gt; -10){
  
  if(count1 &lt; 10 &amp;&amp; count1 &gt; -10) count1 = count1 + (sample(c(1,-1), 1, prob = c(.55,.45)))
      else count1 = count1
  
    if(count2 &lt; 10 &amp;&amp; count2 &gt; -10) count2 = count2 + (sample(c(1,-1), 1, prob = c(.55,.45)))
      else count2 = count2
  
      l_RWM = append(l_RWM,count1)
      r_RWM = append(r_RWM,count2)
  
   }
  </code></pre>
  
  <p>My "if" code is supposed to only have the count occur when the object hasn't reached 10 or -10. E.G. count2 will still count up or down even when count1 has finished. My code doesn't work and I am not looking for an answer but more so a reason to why it doesn't. Keeping in mind that I am very new to R and I apologise in advance if this question is trivial :p. </p>
  
  <p>For anyone wondering, the reason I need them in the same loop is because I'm looking to have something like: if count1 increases than count2 decreases. </p>
  
  <p>Thanks</p>