The problem:
The main structure of the code the way I want it to be-
Def main()
decl int i
decl char arr[3]
INI
PTP HOME ...
arr[1]='w()'
arr[2]='e()'
arr[3]='l()'
for i=1 to 3
arr[i]
endfor
END
def w()
PTP P1 ...
END
def e()
PTP P2 ...
END
def l()
PTP P3 ...
END
Now, as you can see, what i want to do is, have names of SubPrograms stored in an array, and basically call them one by one in a loop. (I could write the SubPrograms one by one and just remove the loop altogether, but after calling every program i have to give a command, and i'm looking for a way where i don't have to write that command everytime, which can be done by using a loop)
The problem is I can't figure out how to store names of the Subprgrams in an array as the above code gives a syntax error.
If there is a different way altogether of calling functions in a loop, I'd be happy to hear about it. else, I'd appreciate the help here.
Thanks :)
Or if you want to use int in several Places:
DEF CallFunc(i : IN)
DECL INT I
switch i
case 1
w()
case 2
e ()
case 3
l()
endswitch
END
DEF w()
;MOVE
END
DEF e()
;MOVE
END
DEF l()
;MOVE
END
And Call it anywhere:
DEF main ( )
FOR I = 1 TO 3
CallFunc(i)
ENDFOR
END
You could implement a switch/case inside your for loop to mimic array indexing.
Def main()
decl int i
decl char arr[3]
INI
PTP HOME ...
for i=1 to 3
switch i
case 1
w()
case 2
e()
default
l()
endswitch
endfor
END
def w()
PTP P1 ...
END
def e()
PTP P2 ...
END
def l()
PTP P3 ...
END
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.