You made a mistake with theta theta<-c(0.08,0.06,0.09,0)
This should be (see the fortran) theta<-c(0.06,0.08,0.09,0) The innermost loop (for( k in ...) is better written as while loop to take into account how Fortran handles loops (see the previous replies): k <- i while( k <= j-1 ){ a<-a*theta[k] k <- k + 1 } Berend -- View this message in context: http://r.789695.n4.nabble.com/LOOping-problem-with-R-tp2399596p2399709.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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.