title: Printing formatted outputs in R
body: <p>Is it possible to print code that is formatted in the following way:</p>
  
  <pre><code>Iteration 1:
  # A matrix goes here
  Iteration 2:
  # Another matrix goes here
  Iteration 3:
  # Another...
  Iteration 4:
  # Last matrix
  
  
  # Final matrix is printed again
  </code></pre>
  
  <p>My function is supposed to print in such a way if my variable verbose is true. All the matrices are stored in a list. Here's my code:</p>
  
  <pre><code>converge &lt;- function(A, eps = 1e-6, itmax = 100, verbose = TRUE) {
    counter &lt;- 1
    iterations &lt;- list()
    B0 &lt;- compute.B(A, 1)
    iterations[[1]] &lt;- B0
  
    if (itmax == 1) {
      return(B0)
    }
  
    for (i in 2:itmax) {
  
      B1 &lt;- compute.B(A, i)
  
      if (sqrt(sum((B1 - B0)^2)) &lt; eps) {
        break()
      }
  
      B0 &lt;- B1
      iterations[[i]] &lt;- B1
      counter &lt;- counter + 1
    }
  
    # Shows last four iterations
    if (verbose &amp;&amp; counter &gt;= 4) {
      for (i in (counter - 3):counter) {
        print(iterations[[i]])
      }
    }
  
    return(B1)
  }
  </code></pre>