[imperative] blocks behaviour

I am trying to run a simple imperative block

i=0;
a={};

[Imperative]
{
while(i <=6)
{
a[i] = i;
i = i+1;
}
}
i;

The block keeps working fine if i increase i <=5 to i <=6 etc. the block returns i=7.
However if I try to decrease it, let’s say i<=3, “i” value remains stuck at the highest value i did before (i=7 in this example).
Is it a bug or am I missing something?

The imperative block has a separate scope (or context of variables) and only it gets re-run after you make changes. Try putting the initial definitions of “a” and “i” inside the imperative block and see if that helps.

Seems to work for now, thank You.