I use: for (m in beg %:% end) {...} where "%:%" <- function(a, b) if (b >= a) a:b
-- David Brahm ([EMAIL PROTECTED]) -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Dominick Samperi Sent: Wednesday, August 23, 2006 11:13 AM To: r-devel@r-project.org Subject: [Rd] Strict seq: a recommendation 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++. To get the proper C/C++ semantics I use the following replacement for seq: seqStrict <- function(beg, end, step=1) { if((beg >= end && step > 0) || (beg <= end && step < 0)) val <- c() # null vector else val <- seq(beg,end,step) val } Perhaps it would be useful to add an option to seq, so seq(beg,end,strict=TRUE) amounts to the same thing as using seqStrict(beg,end). ds ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel