Reusing Local Variable

Certified Senior Developer

Hi Everyone,

I have a requirement where i can reuse local variable array. For Example

a!localvariable(

local!iterations:{1,2,3},

local!value,

a!foreach(

items:local!iterations,

expression{

append(

local!value,

fv!index

)}))

The output i need is

1st Iteration

1

2nd Iteration

1

2

3rd Iteration

1

2

3

But the output the code is generating is

1st Iteration

1

2nd Iteration

2

3rd Iteration

3.

I thought that local variable should be append with the value and  can use for next iteration but it is initializing every time with null value rather than appendvalue. Could you please help me to get the output i need

Thanks In Advance!!!

  Discussion posts and replies are publicly visible

Parents Reply Children
  • 0
    Certified Lead Developer
    in reply to Gopu Hema

    I think you have a fundamental misunderstanding of what local variables are and what they do (and what they don't do).  And what happens when functions act upon them.

    A slightly simpler example:  If you have a local variable of "local!asdf: {1, 2, 3}" for instance - and you call append() on it:  the result of append() is simply an output of the resulting value, it does not (nor would it ever) modify the original local variable it was acting upon.