s-news
[Top] [All Lists]

Re: Stupid question on if ... else ...

To: Jeffrey Wang <jwang@xcaliber.com>
Subject: Re: Stupid question on if ... else ...
From: Spencer Graves <spencer.graves@PDF.COM>
Date: Mon, 18 Aug 2003 08:46:16 -0700
Cc: s-news@wubios.wustl.edu
References: <D5C377ECA6DD12478267E89585EE642C327790@chi-mail2.win.xcaliber.com>
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20030208 Netscape/7.02
Have you tried enclosing the entire "if ... else" construction in parentheses:

(if (length(2) == 1) {
        tmp = 1
}
else {
        tmp = 2
})

          Note that the following phrase is syntactically complete in itself:

if (length(2) == 1) {
        tmp = 1
}

If this gets evaluated by itself before the "else" is encountered, I get an error message. By enclosing the entire "if ... else" construction in parentheses, the processor knows that the phrase in not syntactically complete before "else" is encountered. I'm pretty sure I saw this in a book by Venables and Ripley, but I can't find the reference right now.

hope this helps.  spencer graves

Jeffrey Wang wrote:
        For all my life, I used if ... else ... in the following syntax:

if (length(2) == 1) {
        tmp = 1
} else {
        tmp = 2
}

        However recently, this stopped working for me if this is sourced in as 
a part of file (it still works if I run it from the script window). I had to 
change it as follows in my file:

if (length(2) == 1) {
        tmp = 1
} else {
        tmp = 2
}

        Can someone explain this to me what might be the cause? Thanks for any 
hints in advance.

P.S. I am using S+ 6.1 release 1 on Windows 2000 if it helps.

----
Jeffrey Wang Ronin Capital LLC
Chicago, IL 60604
Tel: (312) 244-5768
Fax: (312) 244-5836
--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu.  To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message:  unsubscribe s-news



<Prev in Thread] Current Thread [Next in Thread>