Can you explain why it is better?
It is better because it is syntactically correct. The first method you mention, though it kinda-sorta looks like it works, does not leave the subroutine intact as an element. This COULD cause issues.
Normally, a subroutine is a block that will be ignored by processing unless it is called by the GoSub> function. Using the method you have invented, the subroutine block is unrecognized and normal processing will run through the subroutine's lines as if it was an average non-subroutine part of the script.
Here's an example script that contains a good subroutine and a bad subroutine. The good uses labels to jump the the last line of the subroutine when conditions are met, while the bad uses subroutine END blocks to pop out of the subroutine. Step through this one line at a time by pressing F8 in the editor and you can see exactly what is happening. The initial subroutine processing will take place correctly with the bad subroutine, but the script processing will run the subroutine again when the GoSub> function has not been called.
To be fair, this could probably be circumvented by placing the subroutine at the end of the script and making sure there is an Exit> function ahead of the subroutine.
Was my fear of compiling confusion correct?
I can be confused. Compilers can only be misinformed.
Hope this makes sense,
Dick
Code: Select all
Let>kk=0
Let>Answer1=0
Let>answer2=0
Label>StartRight
Add>kk,1
If>kk>2,ContinueRight
GoSub>RightWay
Goto>StartRight
Label>ContinueRight
Let>kk=1
SRT>RightWay
If>kk=1
Add>Answer1,1
Else
Add>Answer2,1
Goto>End_RightWay
EndIf
If>kk=2
Add>Answer1,1
Else
Add>Answer2,1
Goto>End_RightWay
EndIf
Label>End_RightWay
END>RightWay
MDL>Right answers are:%CRLF%Answer1=%Answer1%%CRLF%Answer2=%Answer2%
Let>kk=0
Let>Answer1=0
Let>answer2=0
Label>StartWrong
Add>kk,1
If>kk>2,ContinueWrong
GoSub>WrongWay
Goto>StartWrong
Label>ContinueWrong
Let>kk=1
SRT>WrongWay
If>kk=1
Add>Answer1,1
Else
Add>Answer2,1
END>WrongWay
EndIf
If>kk=2
Add>Answer1,1
Else
Add>Answer2,1
END>WrongWay
EndIf
END>WrongWay
MDL>Wrong answers are:%CRLF%Answer1=%Answer1%%CRLF%Answer2=%Answer2%