Message-ID: <Pine.GSO.4.21.0203210819410.19963-100000@fisher.byu.edu>
Date: 2002-03-21T15:22:26Z
From: Greg Snow
Subject: how does while work
In-Reply-To: <016f01c1d046$e9fdd860$768f1941@columbus.rr.com>
On Wed, 20 Mar 2002, jimi adams wrote:
> 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
> }
> }
If you are trying to jump out of a for loop early then try something like:
for (i in 1:101) {
i -> x
if (! x<100 ) { break }
x -> a
}
the "next" command will also skip the rest of the body of the loop and
start on the next iteration.
Hope this helps,
--
Greg Snow, PhD Office: 223A TMCB
Department of Statistics Phone: (801) 378-7049
Brigham Young University Dept.: (801) 378-4505
Provo, UT 84602 email: gls at byu.edu
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._