Help with arrays for shortening scripts?

I’m still fairly new to the Mikrotik scripting language and I find the wiki not always the easiest and most helpful resource, so i’m hoping can someone can quickly clarify something for me

I have some scripts that run and use fixed variable names, scripts such as checking if an interface is up end-to-end rather than just relying on the first hop. Many of these scripts have multiple sections that are all identical with 1 number changed in the variable name, i.e…(in pseudo code)

PingResultISP1 = (ping UpCheckISP1 interface=ISP1)
if PingResultISP1 < 1 then (increase route distance ISPRoute1)
PingResultISP2 = (ping UpCheckISP2 interface=ISP2)
if PingResultISP2 < 1 then (increase route distance ISPRoute2)
PingResultISP3 = (ping UpCheckISP3 interface=ISP3)
if PingResultISP3 < 1 then (increase route distance ISPRoute3)

I want to change this to

NumberOfGateways = 3
for n = 1 to 3
   PingResultISP[n] = (ping UpCheckISP[n] interface=ISP[n])
   if PingResultISP[n] < 1 then (increase route distance ISPRoute[n])
next n

Can someone help me out regarding syntax of arrays in the scripting language and the appropriate way to use them?

bump

Arrays are comma separated.

Here is an example how you can use them:

:local myarray [:toarray value="abc,def,ghi"];
:put $myarray;

:put ($myarray->0);
:put ($myarray->1);
:put ($myarray->2);

:foreach element in=$myarray do={
    :put $element
}

:for counter from=0 step=1 to=2 do={
    :put ($myarray->$counter)
}

Chapter “Operations with Arrays” from https://wiki.mikrotik.com/wiki/Manual:Scripting
http://forum.mikrotik.com/t/array-script/63476/1

Ask “Uncle Google” for “script mikrotik arrays”. You will be amazed how many examples you can find.