title: Does R have a way to say "do n times" without having to write a for loop with a redundant variable?
body: <p><a href="https://codereview.stackexchange.com/q/255232/226217">I recently wrote</a> this line of code: <code>for(i in seq_len(exponent)){out&lt;-squareMat%*%out}</code>. Clearly, <code>i</code> is never used and I just wanted to say &quot;<code>exponent</code> times, do <code>out&lt;-squareMat%*%out</code>&quot;. Was there a way to do this without the redundant counter <code>i</code>? For example, is there an <code>apply</code> family function for this?</p>
  <p>Example - I have:</p>
  <pre><code>squareMat&lt;-matrix(c(0,10,20,30),2,2)
  out&lt;-diag(nrow = nrow(squareMat))
  exponent&lt;-5
  for(i in seq_len(exponent)){out&lt;-squareMat%*%out}
  out
  </code></pre>
  <p>What I want is:</p>
  <pre><code>squareMat&lt;-matrix(c(0,10,20,30),2,2)
  out&lt;-diag(nrow = nrow(squareMat))
  exponent&lt;-5
  [do exponent times]{out&lt;-squareMat%*%out}
  out
  </code></pre>