0

I am facing an error in following script :

i=1
    if(i==1)
    {
        print("done")
    }
    else
    {
        print('Not done')
    }

Error which I am getting :

script.R:6:1: unexpected 'else'
5: }
6: else

But when I make the script a function, i.e. :

f=function()
{
    i=1
    if(i==1)
    {
        print("done")
    }
    else
    {
        print('Not done')
    }
}

It runs just fine. Am I doing anything wrong in my first script or this is an expected behaviour?

The answer here to change the bracket works, but can anyone pls share why this inconsistency ?

user7598713
  • 51
  • 1
  • 6

1 Answers1

0

You need to change your curly brackets as follows :

i=1
    if(i==1)
    {
        print("done")
    }else
    {
        print('Not done')
    }
pseudo_teetotaler
  • 1,485
  • 1
  • 15
  • 35