7.4 Recursive For Loop

There are usually multiple ways of figuring out how to calculate certain items.

For example, consider a different function defined as:

compound <- function(i1, t1){
  (1 + i1)^t1
 }

Editing the code from subsection 7.2, this loop looks like:

i <- 0.05
  for (t in 1:6){
  print(compound(i,t))
}

Instead of finding the results in this way, we could have calculated it as follows:

i <- 0.05
y <- 1
  for (count in 1:6){
  y <- (1 + i)*y
  print(y)
}

The variable \(count\) in the loop is included as a counter, i.e. the loop iterating 6 times. Mathematically, you may want to show why this approach is equivalent to that previously.