I have never successfully utilized loops within Action Script. In fact, I cannot find foreach defined in the Action Script language reference.
Instead I would recommend implementing your loop and related logic into a separate script (i.e. Bash, PowerShell, etc.) and executing via wait command and having error checking immediately following.
For example, the following lines of Action Script are from my Linux-WatchDog install fixlet for BESRelays.
// Inspect crontab tmp file for watchdog keywords & insert record if necessary
if {if (exists file "/var/opt/BESTools/crontab.tmp") then (if (not exists (lines whose (it contains "besrelay_watchdog.sh") of file "/var/opt/BESTools/crontab.tmp" as trimmed string)) then (True) else (False)) else (False)}
wait sudo su - root -c "echo \"@hourly /var/opt/BESTools/besrelay_watchdog.sh\" >> /var/opt/BESTools/crontab.tmp; crontab /var/opt/BESTools/crontab.tmp"
parameter "__ExitCode5" = "{if exist exit code of action then exit code of action as string else "995"}"
if {parameter "__ExitCode5" != "0"}
exit {parameter "__ExitCode5"}
endif
endif
Agree with Casey, there is no built-in loop construct in ActionScript. It is pretty common practice to emulate a loop though, by building a batch file or shell script containing each thing you’d want to “loop” on-the-fly.
Given that %0d%0a is the Carriage Return / Line Feed combination used to mark the end of a line in a Windows file, we could create and execute a batch the following way. For Linux shell scripts you’d terminate the end-of-line with a single %0a character instead.
delete __appendfile
appendfile {concatenation "%0d%0a" of (<relevance expression returning multiple values that are executables or batch command lines>)}
move __appendfile MyBatchScript.cmd
wait cmd.exe /c MyBatchScript.cmd
You can also call a CMD “for” command (or PowerShell Cmdlet) to loop through results of relevance substitution. For this example I created various folders with the name starting TEST then this action script command deletes them via a CMD “for” loop
run cmd.exe /k "for %a in ({concatenation " " of pathnames of folders whose (name of it starts with "TEST") of folder "C:\TEMP"}) do rmdir %a /q