title: Difference of print and return in R?
body: <p>I have defined a factorial function. The script goes like this: </p>
  
  <pre><code>fac &lt;- function(x) {
    f=1
    for (i in 1:x) {
      f = f * i
      print(f)
    }
    print(f)
  }
  </code></pre>
  
  <p>If fac(5), then the output looks like this :</p>
  
  <pre><code>[1] 1
  [1] 2
  [1] 6
  [1] 24
  [1] 120
  [1] 720
  [1] 5040
  </code></pre>
  
  <p>But when I change the 'print(f)' parts into 'return(f)' the output is : </p>
  
  <pre><code>[1] 1
  </code></pre>
  
  <p>Why does this happen? Is there a difference between print and return in R? </p>