While loop working with TRUE/FALSE?
Le mercredi 01 f?vrier 2012 ? 07:55 -0800, Chris82 a ?crit :
Hi R users,
is there any possibilty that a while loop is working like that:
z <- c(0,1,2,3,4,5,6,7,8,9)
r <- 7
while(w == T) {
for ( i in 1:10 ){
w <- r == z[i]
print(w)
}
}
What problem are you trying to solve? In R, loops should generally be avoided, and you have much simpler syntax for most cases.
The loop should stop if w == TRUE
Your while loop stops when w == FALSE here. Anyway, it won't run since w isn't set the first time the condition is tested. And I really don't see why you have two embedded loops here. Cheers