ENDIF cannot occur before a corresponding IF, since its purpose is to terminate the IF statement. Here is an example of a correct IF statement:
if x > 3 a = 1 elseif x > 2 a = 2 else a = 3 endif
See Also Errors