[S] while

David Wang (SWANG@vtvm1.cc.vt.edu)
Fri, 06 Feb 98 09:54:58 EST


Thank you very much for those who responded to my question about "while"
It's just a careless mistake on my part.

I did not reset the value of i after you complete the inner loop.
It should be:

j <- 1
while(j <= 20){
i <- 1
while(i <= 20){
tox[i,j] <- "my calculation"
i <- i +1
}
j <- j+1
}

Many suggested to use the for loop, which is more efficent than "while"

for (j in 1:20)
for (i in 1:20)
tox[i,j] _ "my calculation"

My original request:

> Dear S+ users,
>
> I wrote a program to update the values of a matrix by using
> two while statement. But the outer loop does not change and stay at the
initial
> value.
>
> Thank you for any comments or suggestion.
>
> The program follows:
> tox <- matrix(0,20, 20)
> i <- 1
> j<-1
> while(j <= 20){
> while(i <=20){
> tox[i,j] <- "my calculation"
> i <- i +1}
> j <- j+1}
>
> Note: the j loop just goes 1 time.
>
>
> David
> -----------------------------------------------------------------------
>

THANK YOU VERY MUCH

David
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news