Skip to content

if/else at 1.3.1

2 messages · john_heumann@agilent.com, Brian Ripley

#
Under NT with 1.3.1

if (x == 1) {
  cat("Saw x=1\n");
} else {
  cat("Saw x!=1\n");
}

works as expected, but 

if (x == 1) {
  cat("Saw x=1\n");
} 
else {
  cat("Saw x!=1\n");
}

is currently giving me a syntax error on the "else" line. 
Apparently the parser considers the if statement to have 
ended as soon as it sees first closing brace, unless 
there's an else on the same line.

IIRC, both forms were accepted at 1.3.0. Is this a bug, 
or intentional? I don't see any mention of this
change in the "What's New" notes. BTW, I didn't notice
this behavior until after a crash (caused by a known
package bug) which blew me all the way out of RGui, 
so its possible I've corrupted my installation...

Thanks,
-jh-

=========================================
John M. Heumann, Agilent Technologies
815 14th St. S.W., Loveland, CO 80537 USA
Email: john_heumann at agilent.com
Phone: 970 679-3761 FAX: 970 679-5399
=========================================
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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, 17 Oct 2001, HEUMANN,JOHN (A-Loveland,ex1) wrote:

            
Right, that is as described in the R Language Reference Manual, e.g.
in section 10.2.5.

All R statements are considered ended at the first new line at which they
are syntactically complete.
If it worked in 1.3.0, that was a bug, as it was documented otherwise in
that version too.
I've never seen a syntax error crash RGui.  If that is all that there is
to this, please file a bug report.