Re: [R] executing loop in circular way

2010-09-09 Thread jim holtman
try this: i <- 0 n <- 10 repeat{ cat(i + 1) # use the value; add 1 since we start at zero i <- (i + 1) %% n } On Thu, Sep 9, 2010 at 12:53 PM, cassie jones wrote: > Dear all, > > I am writing a program using for loop. The loop contains i which runs from > 1:n. There is a feature I ne

[R] executing loop in circular way

2010-09-09 Thread cassie jones
Dear all, I am writing a program using for loop. The loop contains i which runs from 1:n. There is a feature I need to include here. That is, when i=n, i+1 would be 1, not n+1. Basically the loop should run in a circular fashion. That also means, if i=1, i-1=n. Can anyone help me with this? How c