you can use break :
for(i in 1:5) {
     #e.g.
     a <- sample(1:10, 1)
     # important part :
     if(a==3) break
}
a

or while :
a <- 0
while(a != 3){
     # an operation that change a :
a <- sample(1:10, 1)
}

Etienne

Le 2010-04-05 10:46, Ravi S. Shankar a écrit :
> Hi R,
>
>
>
> I am running a for loop in which I am doing a certain calculation. As an
> outcome of calculation I get an out put say "a". Now in my for loop "I"
> needs to be initiated to "a".
>
>
>
> Based the below example if the output "a"=3 then the second iteration
> needs to be skipped. Is there a way to do this?
>
> for(i in 1:5)
>
> {
>
> ##Calculation##
>
> a=3 ## outcome of calculation
>
> }
>
>
>
> Any help appreciated. Thanks in advance for the time!
>
>
>
> Regards
>
> Ravi
>
>
>
> This e-mail may contain confidential and/or privileged i...{{dropped:13}}
>
> ______________________________________________
> R-help@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.
>    

	[[alternative HTML version deleted]]

