You can loop through For Next loop in the script:
Find below sample snippet
SUB DoDir (Root)
FOR Each File in filelist (Root&' \*.qvd')
let numRows = QvdNoOfRecords('$(File)');
let table = QvdTableName ('$(File)');
load * inline [
FOR Each Dir in dirlist (Root&' \*' )
call DoDir (Dir)
CALL DoDir ('C:')
There are two parts in this piece of code. A SUB...END SUB definition which defines but doesn't execute a callable procedure, and the CALL of that same SUB (last line) which executes the procedure with a starting directory as parameter.
Always put the definition before the first CALL or you will get a script error. You can put the definition on the first script tab (together with any other SUB definition), and CALL it anywhere else on the following tabs.