Re: [R] multiple "next" in for loops?

From: Duncan Murdoch <murdoch_at_stats.uwo.ca>
Date: Tue, 11 Nov 2008 21:18:48 -0500

On 11/11/2008 8:16 PM, remko duursma wrote:
>
> Dear R list,
>
>
> I was wondering if there is an easy fix to this problem (there are workarounds, as always):
>
> Within a for loop, we can use "next" to skip to the next index,
> but how can we skip the next n indices?
>
> So, I would like something that looks like;
>
> for(i in 1:10){
>
> if(somecondition)next(5)
>
> }
>
> Is there a way?

Don't use a for loop, use a while loop:

i <- 1
while (i < 11) {

   if (somecondition) i <- i+5
   else {

     blah blah blah
     i <- i+1

   }
}

Duncan Murdoch



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 12 Nov 2008 - 02:25:24 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 12 Nov 2008 - 02:30:25 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive