[R] for loop doesn't stop with upper loop value

Alexander.Herr at csiro.au Alexander.Herr at csiro.au
Wed Jul 4 02:01:00 CEST 2007


Hi list,

could anyone please educate me on the following:

lst<-seq(47, 239, by=12)

for(n in lst)
{
  lower=n; upper=lower+10
   for(i in lower+2 : upper) 
   { 
     print(paste(n, " i: ", i, " lower: ",lower, " upper :", upper))
   }  
}

does not stop when i = upper


A while loop fixes this but, I still don't understand why the for loop
doesn't stop when I has the value of upper


for(n in lst)
{
  lower=n; upper=lower+10
   while(lower !=upper +1)
   { 
    print(paste(n, " lower: ",lower, " upper :", upper))
     lower=lower+1
   }  
}

Any enlightment would be most welcome.

Thankx 
Herry



More information about the R-help mailing list