Hi everyone! May I request again for your help? I need to make some codes using if else statements... Can I do an "if-else statement" inside an "if-else statement"? Is this the correct form of writing it? Thank you.=) Example: for (v in 1:6) { for (i in 2:200) { if (v==1) (if max(x*v-y*v)>1 break()) if (v==2) (if max(x*v-y*v)>1.8 break()) if (v==3) (if max(x*v-y*v)>2 break()) } } -- View this message in context: http://n4.nabble.com/If-else-statements-tp1678705p1678705.html Sent from the R help mailing list archive at Nabble.com.
Here are some references. Please read these first and post again if you are still stuck after reading them. If you do post again, we will need x and y. 1. Introduction to R : 9.2.1 Conditional execution: if statements. 2. R Language Definition : 3.2 Control structures. 3. R for beginners by E Paradis : 6.1 Loops and vectorization 4. Eric Raymond's essay "How to Ask Questions The Smart Way" http://www.catb.org/~esr/faqs/smart-questions.html. HTH Matthew "tj" <girlme80 at yahoo.com> wrote in message news:1269325933723-1678705.post at n4.nabble.com...> > Hi everyone! > May I request again for your help? > I need to make some codes using if else statements... > Can I do an "if-else statement" inside an "if-else statement"? Is this the > correct form of writing it? > Thank you.=) > > Example: > > for (v in 1:6) { > for (i in 2:200) { > if (v==1) > (if max(x*v-y*v)>1 break()) > > if (v==2) > (if max(x*v-y*v)>1.8 break()) > > if (v==3) > (if max(x*v-y*v)>2 break()) > } > } > -- > View this message in context: > http://n4.nabble.com/If-else-statements-tp1678705p1678705.html > Sent from the R help mailing list archive at Nabble.com. >
Thanks Matthew... I will read your suggested articles/files. I hope, i will be able to figure out what should be done with this. =) ~tj -- View this message in context: http://n4.nabble.com/If-else-statements-tp1678705p1679073.html Sent from the R help mailing list archive at Nabble.com.
The short answer is yes, you can, but your syntax is wrong. You need to make sure you wrap your conditions inside brackets, and use {, not (, to delineate your if statements.> for (v in 1:6) { > for (i in 2:200) { > if (v==1){if (max(x*v-y*v)>1) break() } } } et cetera On Tue, Mar 23, 2010 at 3:32 AM, tj <girlme80 at yahoo.com> wrote:> > Hi everyone! > May I request again for your help? > I need to make some codes using if else statements... > Can I do an "if-else statement" inside an "if-else statement"? Is this the > correct form of writing it? > Thank you.=) > > Example: > > for (v in 1:6) { > for (i in 2:200) { > if (v==1) > (if max(x*v-y*v)>1 break()) > > if (v==2) > (if max(x*v-y*v)>1.8 break()) > > if (v==3) > (if max(x*v-y*v)>2 break()) > } > } > -- > View this message in context: http://n4.nabble.com/If-else-statements-tp1678705p1678705.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >