+ 2
Can someone explain me , Where 't' variable is initialized.?
public class Program { public static void main(String[] args) { int[ ] primes = {2, 3, 5, 7}; for (int t: primes) { System.out.println(t); } } } /* 2 3 5 7 */
5 Respostas
+ 6
for(int t : primes) runs through every element in primes and assigns it to t.
+ 1
whenever you see such kind of For loop declaration, you got to understand that every value of the array is executing in the loop through assignment to 't'.
+ 1
:t will assign every elements of the array of each iteration, it shall transverse them
- 1
in enhanced for loop t is initialized
- 1
in enhanced for loop, the variable t is declared within the condition it self..
the value of t starts from 2 then 3 and so on in every iteration..
I,e in every iteration it gives out the values stored in the array primes stating from the very first one..
so in a way the value if t is initialized in the very first iteration when t becomes equal to 2