In R, loops are often not the most efficient way to do repetitive calculations. Rather than doing the calculations for each value of a variable it is much more efficient to organize the values of that variable in a vector (or array) and do the calculations on the entire vector. In this video we illustrate the difference between a vectorized calculation and a loop and demonstrate the speed advantage that the former form of calculation typically offers. Whenever you write R code involving a loop, it is worth considering whether you can re-write the code in a vectorized way to avoid the loop. If so, such a change is typically worthwhile.
You should follow along with Examples 9a and 9b in Mod11Script.R when watching this video, which is essential content for the course.