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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
how does while work
4 messages · jimi adams, Giovanni Petris, Greg Snow +1 more
assuming you enter the while loop with a value of x less than 100, the for loop sets, in its last iteration, a=x=101 (which is the last value `i' takes). at this point you also exit the while loop, since x<100 is false. Giovanni
From: "jimi adams" <imij at columbus.rr.com>
Date: Wed, 20 Mar 2002 14:39:13 -0500
X-Priority: 3
X-MSMail-Priority: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
Sender: owner-r-help at stat.math.ethz.ch
Precedence: SfS-bulk
Content-Type: text/plain;
charset="iso-8859-1"
Content-Length: 1205
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
__________________________________________________ [ ] [ Giovanni Petris GPetris at uark.edu ] [ Department of Mathematical Sciences ] [ University of Arkansas - Fayetteville, AR 72701 ] [ Ph: (479) 575-6324, 575-8630 (fax) ] [ http://definetti.uark.edu/~gpetris/ ] [__________________________________________________] -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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
}
*here*
}
Essentially the while condition doesn't get checked until just before the last curly brace (where I inserted *here* above), so the for loop gets to do it's thing until i (and x and a) reach 101 and only then is the while condition allowed to drop you out of the loop.
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...
what exactly are you trying to do? daver +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |David Richmond It works on a | + Dept. of Sociology complex scientific + |Saint Mary's College principle, known as | + Notre Dame, IN 46556 "pot luck." + |574-284-4517 - The Doctor | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._