Array values getting set for next index

I am trying to set array values by looping and with some condition. What I observe is if I am setting say array index 100 to some value - automatically Amibroker is setting array index 101 with same value - this seems unexpected.
Pasting my code below and result of Log window. I want to understand why Amibroker is behaving this way.

#pragma enable_static_decl("{symbol}{chartid}");
SetBarsRequired(sbrAll, sbrAll );
static  test;

test[0] = 1;
index = BarIndex();
this_index = index[BarCount-1];
_TRACE(StrFormat("idx %g Current value %g" ,this_index, test[this_index]));
if (this_index %2) { 
	new_val = 1;
}  else {
	new_val =2;
}
test[this_index] = new_val;

Log window output:

idx 9 Current value 1 Formulas\Custom\Formula 36.afl 8 17 18:19:46.85
idx 9 Current value 1 Formulas\Custom\Formula 36.afl 8 17 18:19:47.38
idx 9 Current value 1 Formulas\Custom\Formula 36.afl 8 17 18:19:47.71
idx 9 Current value 1 Formulas\Custom\Formula 36.afl 8 17 18:19:47.90
idx 9 Current value 1 Formulas\Custom\Formula 36.afl 8 17 18:19:48.41
idx 9 Current value 1 Formulas\Custom\Formula 36.afl 8 17 18:19:48.72
idx 9 Current value 1 Formulas\Custom\Formula 36.afl 8 17 18:19:48.94
idx 9 Current value 1 Formulas\Custom\Formula 36.afl 8 17 18:19:49.47
idx 9 Current value 1 Formulas\Custom\Formula 36.afl 8 17 18:19:49.73
idx 9 Current value 1 Formulas\Custom\Formula 36.afl 8 17 18:19:49.99
idx 9 Current value 1 Formulas\Custom\Formula 36.afl 8 17 18:19:50.51

Advance index value getting set

|idx 10 Current value 1|Formulas\Custom\Formula 36.afl|8|17|18:19:50.74|

Later as we overwrite the value to 2, the value get set correctly as below

|idx 10 Current value 2|Formulas\Custom\Formula 36.afl|8|17|18:19:51.02|
|idx 10 Current value 2|Formulas\Custom\Formula 36.afl|8|17|18:19:51.52|
|idx 10 Current value 2|Formulas\Custom\Formula 36.afl|8|17|18:19:51.74|
|idx 10 Current value 2|Formulas\Custom\Formula 36.afl|8|17|18:19:52.05|
|idx 10 Current value 2|Formulas\Custom\Formula 36.afl|8|17|18:19:52.55|
|idx 10 Current value 2|Formulas\Custom\Formula 36.afl|8|17|18:19:52.74|
|idx 10 Current value 2|Formulas\Custom\Formula 36.afl|8|17|18:19:53.08|
|idx 10 Current value 2|Formulas\Custom\Formula 36.afl|8|17|18:19:53.60|
|idx 10 Current value 2|Formulas\Custom\Formula 36.afl|8|17|18:19:53.74|
|idx 10 Current value 2|Formulas\Custom\Formula 36.afl|8|17|18:19:54.13|
|idx 10 Current value 2|Formulas\Custom\Formula 36.afl|8|17|18:19:54.63|
|idx 10 Current value 2|Formulas\Custom\Formula 36.afl|8|17|18:19:54.74|
|idx 10 Current value 2|Formulas\Custom\Formula 36.afl|8|17|18:19:55.15|
|idx 10 Current value 2|Formulas\Custom\Formula 36.afl|8|17|18:19:55.66|
|idx 11 Current value 2|Formulas\Custom\Formula 36.afl|8|17|18:19:55.74|
|idx 11 Current value 1|Formulas\Custom\Formula 36.afl|8|17|18:19:56.18|
|idx 11 Current value 1|Formulas\Custom\Formula 36.afl|8|17|18:19:56.69|