The simplest script ever, so why do I get an error:
> x <- -5
> if(x > 0){
+ print("Non-negative number")
+ }
> else{
Error: unexpected 'else' in "else"
> print("Negative number")
[1] "Negative number"
> }
Error: unexpected '}' in "}"
If I simply put the else after } then there is no problem.
> x <- -5
> if(x > 0){
+ print("Non-negative number")
+ } else{
+ print("Negative number")
+ }
[1] "Negative number"
Thing is I have always written it the first way without problem; am I going crazy?
Aucun commentaire:
Enregistrer un commentaire