GOTO to a return in a subroutine amidst multiple If-Then's
Are there any caveats to using multiple GOTOs to a single return from within IF-THEN-ELSE's in a subroutine? I am using it to skip irrelevant code once the first condition is met.
Example (for reference only, not trying to actually do anything):
Code:
carry_out_logic:
if counter=4 then
toggleme=~toggleme
LED_4=1
goto continueon
endif
if counter=6 then
LED_6=1
goto continueon
endif
(...other if-then stuff...)
continueon:
return
I know I can make use of ELSIF to skip irrelevant code, but it just gets really messy to read when dealing with multiple conditions in multiple IF's.
Re: GOTO to a return in a subroutine amidst multiple If-Then's
just say "return".
Whenever it is hit, it will return to last call.
Code:
carry_out_logic:
if counter=4 then
toggleme=~toggleme
LED_4=1
return
endif
if counter=6 then
LED_6=1
return
endif
(...other if-then stuff...)
return ' if nothing executed so far, it returns anyway.
Re: GOTO to a return in a subroutine amidst multiple If-Then's
Your approach to a JUMP sequence at the bottom of a subroutine comes in handy when programming in ASM on older PICs that require Context saving, or when there is one or more other tidy-up duties required before a RETURN, but sayer's method works and it's clean.
Re: GOTO to a return in a subroutine amidst multiple If-Then's
And it saves a few instructions. (faster)