[R] how does while work

Liaw, Andy andy_liaw at merck.com
Wed Mar 20 21:09:57 CET 2002


The for loop is nested inside the while loop, so it is finished before the
next iteration of the while loop is attempted.  So, in short, the for loop
ran 101 times, ending with i, x, and a all equal to 101.  Then the condition
of the while loop is checked, (and not satisfied).

Andy

> -----Original Message-----
> From: jimi adams [mailto:imij at columbus.rr.com]
> Sent: Wednesday, March 20, 2002 2:39 PM
> To: r-help at stat.math.ethz.ch
> Subject: [R] how does while work
> 
> 
> i am having some problems with a program that i am writing 
> and i think that
> knowing how the while command works will help me to figure 
> out where i am
> going wrong
> *when do you get kicked out of a while loop?*
> (i.e., in the following example  what would the final value 
> of 'a' be?) i
> thought it would be 99 but running it in R i get 101 (and 101 
> for x too!)
> 
> while (x <100) {
>   for (i in 1:101) {
>     i -> x
>     x -> a
>   }
> }
> 
> while this is a crude example, it is the basic form of what i 
> am trying to
> do, and i am guessing that while is not what i am looking for...
> 
> jimi adams
> Department of Sociology
> The Ohio State University
> 300 Bricker Hall
> 190 N Oval Mall
> Columbus, OH 43210-1353
> 614-688-4261
> 
> our mind has a remarkable ability to think of contents as 
> being independent
> of the act of thinking
>                                             -georg simmel
> 

> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
> -.-.-.-.-.-.-.-.-
> r-help mailing list -- Read 
> http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: 
> r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
> _._._._._._._._._
> 

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list