Very fast classic BASIC construct.
I will put this macro into the OxygenBasic core language
def on
======
'%1' name of index variale
'%2' goto or gosub or call
'%3' { @label1,@lael2,...}
'$$ reserved name ending
scope
static sys st$$[64]
if not st$$[1]
st$$[1]={%3}
endif
if %1
%2 st$$[%1]
endif
end scope
end def
function f(int v,n=0) as int
============================
'
on n gosub {@sr1,@sr2,@sr3,@sr4}
'
subroutine sr1
--------------
print "sr1"
end subroutine
'
subroutine sr2
--------------
print "sr2"
end subroutine
'
subroutine sr3
--------------
print "sr3"
end subroutine
'
subroutine sr4
--------------
print "sr4"
end subroutine
'
return v
end function
'
'TEST:
int i
for i=1 to 4
f(0,i)
next
Hi Charles,
Have you completed entering these commands into O2?
I would like to include them in my Help.
Anyway, I agree that they can speed up and simplify a program. A sort of IF ... THEN GOSUB/CALL on one line compared to the possible n lines of IF ... THEN ...
Thanks
Hi Nicola,
There is an entry in inf/oxyDatabase.txt. It also appears in the manual.
key: "on 18"
action: on x goto / gosub / call { list }
use: branch to an address using a list of locations
example:
procedure f(int isr)
subroutine sr1
...
end subroutine
subroutine sr2
...
end subroutine
subroutine sr3
...
end subroutine
'
on isr gosub {@sr1,@sr2,@sr3}
'
end procedure
remarks: lists of up to 128 subroutines are supported
related: Procedures ,subroutine, label, gosub, call, goto
group: system macro
updated: 02/03/2025
.
It is defined by an internal macro, which might be quite useful for deriving similar constructs:
def on
'%1' name of index variable
'%2' goto or gosub
'%3' { @label1,@label2,...}
scope
static sys _st_[128]
if not _st_[1]
_st_[1]={%3}
endif
#if not anymatch " goto gosub call ","%2"
#error "Expecting: goto / gosub / call "
#endif
%2 _st_[%1]
end scope
end def