Skip to content
Back to formatted view

Raw Message

Message-ID: <1328112590.3598.45.camel@milan>
Date: 2012-02-01T16:09:50Z
From: Milan Bouchet-Valat
Subject: While loop working with TRUE/FALSE?
In-Reply-To: <1328111722647-4348340.post@n4.nabble.com>

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