+ 19

# [SOLVED] What is this t: primes doing in for(int t:primes) and why is it traversing through the array??

Pls explain t:primes in the for loop.....

5 Antworten

+ 5

In Java this colon ':' character means "for each".In int t : primes. t stores the next element of the primes array if it exists each times the loop runs.

+ 11

Thnk uu

+ 9

Java?
It means -> for each `int` variable as <t> in <primes>.

+ 8

That is short form version of for loop used to traverse array.. It's don't require to mention array length..
int primes[] ={2,3,5,7,11,13};
for(int i : primes)
System.out.println(i);
Its is used for iterables like Arrays, strings, lists...
Edit: in java, pls mention or tag the language

+ 3

Alphin Sajan You're Always Welcome bro.