title: For-loop in R, replacing nth and nth+1
body: <p>I need some help with a for-loop I've been working with. I don't know if what I have done is even possible, but I hope you can help me make it work.</p>
  
  <p>Initially, I have a list of 100 elements, which are all FALSE. 
  I want to pass through 100 variables to change the elements (FALSE/TRUE).
  Step 1 should change every element to TRUE,
  Step 2 changes every second element(starting at 2); if FALSE to TRUE and if TRUE to FALSE,
  Step 3 changes every third element, and so on. </p>
  
  <p>Here is what I have so far: </p>
  
  <pre><code>X = rep(FALSE,100)
  
  for (i in X) {
   if (i == X[1]) {
   X[X%%1==0] == TRUE
   } else {
     i = i+1
     k = X[X%%i==0]
     for (i in k) {
      if (k == TRUE) {
      replace(X, k, FALSE)
    } else {
      replace(X, k, TRUE)
     }
    }
   }
  }
  </code></pre>
  
  <p>Finally I want the outcome to sum all the elements that are TRUE, but I don't know how to put that in the loop. </p>
  
  <p>All help is much appreciated!</p>