FOREACH

hi sir/mam
i am facing an issue that is in foreach loop
my question is
int a[4];
initial
begin
foreach(a[i]) a[i]=i;
foreach(a[i]) $display(“\tValue of a[%0d]=%0d”,i,a[i]);
end
this will print in the form of
Value of a[0]=0
Value of a[1]=1
Value of a[2]=2
Value of a[3]=3

but if int a[3:0] i am declaring this is printing as
Value of a[3]=3
Value of a[2]=2
Value of a[1]=1
Value of a[0]=0

definition of foreach is Foreach loop iterates through each index starting from index 0. but failed when int a[3:0] ? can any one clear me.

In reply to LOHIHTHA DM:

Section 12.7.3 explains that the array bounds are used as iteration limits. With a defined as a[3:0], the index will go from 3 down to 0.

The examples provided in this section demonstrate how the indexes are iterated over the array.