Array Subscript out of Range Error

Hi..
Please find the below code

_SECTION_BEGIN("creating dynamic array");
array=0;
i=0;
while (i<10)
{
array[i]=i;
i=i+1;
}
AddColumn(array,"array values");
_SECTION_END();

When i run the code in the editor it is working fine as expected. But the same code if i run through explorer getting the error as "Array subscript out of range.You must not access array elements outside o barcount-1 range. you attempt to access non existing of 7th element of array." Please let me know the issue. you can reproduce the issue just to run the program in explorer window.
Please find the attachment for more details.Dynamic%20array_error