Many thanks, Alan! You are a gentleman and a scholar.Hi,
No, the Editor/Compiler will probably generate exactly the same code and AFAIK that will actually execute a GOTO (Jump to address).
It's more complicated with a "Conditional Goto", which can exist in numerous forms: IF .. THEN .. ELSE .. ENDIF , IF .. THEN {GOTO} , ON .. GOTO (or BRANCH) , SELECT .. CASE , etc.. Personally, I prefer the IF .. THEN GOTO format because its execution time is completely predictable (the "True" path is about 50% slower than the "False" path); an ELSE adds "unpredictable" delays, and SELECT .. CASE even more. For a multiple branch, the ON .. GOTO is potentially the fastest, if the conditions involve a simple numerical sequence.
Cheers, Alan.
main:
;CODE
goto sub1
flash:
;CODE
goto sub2
sub1:
;CODE
goto flash
sub2:
;CODE
goto main
It will work if you do it right, but no one will maintain that it is "good code practice". Functional is the best you can hope for with GOTO, and as programs grow larger, functionality becomes more tenuous.Is it good code practice to create several labels and use gotos at the end of each one to move to the next ones like this:
Hmm, IMHO better to structure the code correctly and minimise the number of GOTOs. For example:Is it good code practice to create several labels and use gotos at the end of each one to move to the next ones like this:
main:
; CODE
sub1: ; Or just a comment to indicate the next process
; CODE
flash:
; CODE
sub2:
; CODE
goto main
;* OR PERHAPS:
do
call main
call sub1
call flash
call sub2
loop
main:
; CODE
return
; ETC.....
I think that EXIT exits only from do...loop or for...next which are essentially equivalent constructions, and so it does the same thing in each case - i.e. exits the loop. Trying to use EXIT within an if block gives a compiler error (unless it happens to be within a loop, of course)Personally, I do consider EXIT to be rather contrived, when it can mean either "GOTO the line after the next NEXT" OR "GOTO the line after the next ENDIF".
b0= 0
b1 = 100
Do while punc.0 =0"
Do while pinc.0 =0
If b0>b1 then exit
Inc b0
Pause 10
Loop
'do something here
Loop
B1 = 10
Do while pinc.0=0
For b0 = 0 to b1
If pinc.0 = 1 then exit
Pause 10
Next b0
Loop