[Rd] Strict seq: a recommendation
Thomas Lumley
tlumley at u.washington.edu
Wed Aug 23 17:28:44 CEST 2006
On Wed, 23 Aug 2006, Dominick Samperi wrote:
> In for loops of the form:
> for(m in seq(beg,end))
> ...
>
> when beg > end, the default behavior is
> to decrement, and the action described
> by ... is executed at least once.
>
> On the other hand, if you view this
> construction as a translation of the C code:
> for(m = beg; m < end; m++)
> ...
>
> then the semantics of C/C++ is not
> respected, because the code in ... is
> not executed when beg > end in
> the case of C/C++.
There is another important way in which the C loop is different
from the R loop. If you modify m or end inside the loop the number of
iterations of the C loop changes but the number of iterations of the R
loop doesn't. R's for() loop just isn't the same as C's.
-thomas
Thomas Lumley Assoc. Professor, Biostatistics
tlumley at u.washington.edu University of Washington, Seattle
More information about the R-devel
mailing list