2

In the R FAQ's section about comparing S and R, we find the following:

In R, For() loops are not necessary and hence not supported.

What was a For() loop and why does R not need it?

J. Mini
  • 1,868
  • 1
  • 9
  • 38
  • It appears to have been a method of speeding up the normal `for` loop. I suspect that it has been incorporated into the `for` loop in R so it is unnecessary. – dcarlson Apr 11 '21 at 16:40
  • @dcarlson Do you have a source for that? – J. Mini Apr 11 '21 at 20:54
  • I was able to find a copy of [S-PLUS: Programmer’s Guide online](https://www2.stat.duke.edu/courses/Fall99/sta240/PGUIDE.PDF). Check pages 647-648 on `For` loops. The S-Plus manual discourages using 'for` loops and encourages `apply` family approaches, but R seems to have optimized `for` loops to the point that those recommendations are now moot. – dcarlson Apr 11 '21 at 21:39
  • @dcarlson That looks good enough to turn in to an answer. Have at it. – J. Mini Apr 12 '21 at 15:44

1 Answers1

2

There is a copy of S-PLUS: Programmer’s Guide online. Pages 647-648 contrast for and For loops. The S-Plus manual generally discourages using for loops (pp. 120, 639-641) and encourages apply family approaches, but R has optimized for loops to the point that those recommendations are now moot and the "optimized" For loop is no longer necessary.

dcarlson
  • 10,936
  • 2
  • 15
  • 18