[R] Force the for loop to stop
Stephan Kolassa
Stephan.Kolassa at gmx.de
Wed Jun 1 21:34:16 CEST 2011
Hi,
you could set a dummy variable to FALSE outside the outermost loop. If
the break condition is met in the inner loop, set the dummy variable to
TRUE before breaking and test its truth status in the outer loop.
HTH
Stephan
Am 01.06.2011 21:25, schrieb Salih Tuna:
> Hi,
> I am looking for a command in R that would force the for loop to stop after
> it finds what it is looking for.
> As an example
> for(i in 1:5){
> for(j in 3:6){
> if(i==j)
> # do something...
> break;
> }
> }
> And i don't want the loop to execute once i = 3 and stop.
>
> Is there a way to do this?
>
> best,
> salih
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>
More information about the R-help
mailing list