Now I'm not getting paid $100+ per hour to do this, so I didn't bother to even check if your code actually does what you think it does - so maybe GIGO if you have other 'bugs'!
You didn't say WHAT compiler, so I will have to just use general problem solving principles based on about 30 years bloody minded experience with about 30+ languages in many different 'language families'!
Now it doesn't really matter WHAT language you are compiling, the basic principles are ALWAYS the same.
Without knowing just exactly what the compiler is doing internally, let us just assume that is chewing the input, looking for tokens/chunks it recognises so it can digest them.
Now a general "if statement" (irrespective of language - of this sort of computing language family - of course!) has the following generic layout:
[code block A]
If {condition} then
[code block 'then']
else
[code block 'else']
endif
[code block B]
Code blocks A & B are external to the if statement and both are always executed.
You should clearly understand the flow thru the if statement:
either the 'then block' or the 'else block' is executed. If there is no 'else block', then that is of course ignored, and execution either does the 'then block' or does not do it, and then execution always resumes at code block B. Code block B would normally be something of the order 'variable is assigned to be some value'.
Now your coding has 'implied' (not explicit) 'then', 'else' and 'end if' statements.
What is worse, it is not clear whether you want both if statements to be always executed in sequence, or if the 2nd if statement is intended to be 'nested' inside the first if block.
God knows WHAT the compiler really thinks, since you didn't say which one it is... but at a guess, it seems the compiler's default action is to look at the 'variable table' before it consults the 'list of reserved words'...
when it hits the 'return' statement (while it is still trying to digest the 'if statement' block and looking for an 'endif' statement!) in an implied nested 'if then if' statement, it encounters what it thinks is an undeclared variable (called 'return' - which you did not declare!) to be part of a {'variable is assigned to be some value' token/chunk} - hence the error message! :-)
Just bunging a pile of assorted crap into the compiler and saying like a certain Medieval Bishop (who said "kill them all - let God sort them out!" when asked how to sort the Christians from the infidels) 'let the compiler sort it out!' is no substitute for clearly understanding the language and code flow within it, and ensuring that you write explicit code, instead of writing implicit code and ***-U-MEing that the compiler will understand 'what you thought you meant'!
Glad to be of help!
(IQ SD +5)
:-P