3

I'm having a simple R code which returns Error: unexpected 'else' in "else":

if(1==1)
{
    x = 1
}
else
{
    x = 2
}

Can someone please explain how thats possible?

Its a different case than question Unexpected 'else' in "else" error because there the problem appears to be caused by a nested else while here it is unnested.

emcor
  • 284
  • 4
  • 15

1 Answers1

11

typing else on the same line as the closing } solves this problem:

    if(1==1)
{
  x = 1
} else
{
  x = 2
}
Rieneke
  • 151
  • 1
  • 6