Why are arrays usually processed with for loop?

The real power of arrays comes from their facility of using an index variable to traverse the array, accessing each element with the same expression a. All the is needed to make this work is a iterated statement in which the variable i serves as a counter, incrementing from 0 to a.length -1. That is exactly what a loop does.
 
An array, in the context of Java, is a dynamically-created object that serves as a container to hold a constant number of values of the same type. By declaring an array, memory space is allocated for values of a particular type. At the time of creation, the length of the array must be specified and remains constant. That is exactly what a loop does.
 
Arrays are used to store multiple data of the same type in a contiguous memory location. Now to store these data in each index of the array or to do some useful work on them you need to traverse it i.e. go through each index in the array. for-loops are extensively used when working with arrays. To iterate through every value of the array.
 
Back
Top