AnsweredAssumed Answered

Using loop in a function

Question asked by AlfredoMolinolo on Feb 23, 2015
Latest reply on Feb 23, 2015 by AlfredoMolinolo

Title

Using loop in a function

Post

Hi there. I have a script that adds a char string to either the right or the left side of a passed string:

#The script accepts 4 parameters:
#Text to be padded
Set Variable [$String2Pad; Value:Getvalue(Get{ScriptParameter); 1)]
#Char to use to pad
Set Variable [$Char; Value:Getvalue(Get{ScriptParameter); 2)]
#Lenght of the string of Char to use to pad
Set Variable [$CharNumber; Value:GetAsNumber(Getvalue(Get{ScriptParameter); 3))]
#Side of the passed string to which t o add the padding
# "'L"' or no parameters is left; "'R"' is right
Set Variable [$Side2Pad; Value:If(Getvalue(Get{ScriptParameter); 4) = "" ;0;Getvalue(Get(ScriptParameter); 4))]
Loop
     Exit Loop If [$CharNumber = 0]
    Set Variable [$String2Pad; Value:I f($Side 2Pad = i · or $Side 2Pad = -; $Char & $String2Pad;        $String2Pad & $Char)]  

Set Variable [$CharNumber; Value:$CharNumber - 1]

End Loop

The script works well, but I'd like for it to be a function, so I don't have to work with global variables or fields, but I don´t think I can loop within a function, can I?

Thanks!

 

Outcomes