1

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 :)

Battu007
  • 25
  • 1
  • 5

2 Answers2

1

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
kcinnaySte
  • 41
  • 4
0

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
Micahstuh
  • 443
  • 1
  • 5
  • 13
  • 1
    This is what I'm implementing currently. It's not what I was looking for, but hey, as long as it works. – Battu007 Apr 30 '19 at 06:57