What does this means?

If a for loop looks like this, wha does the ' : " in the loop means?

publicstaticvoid printArray( Integer[ ] inputArray)

{

for(Integer element : inputArray)

System.out.println("%s", element);

}

[442 byte] By [geniver82a] at [2007-10-2 14:26:59]
# 1

Well, read the statement out loud. In fact, just say (out loud) what you think the loop does. Just use natural language in your language of choice.

You should have said something like:

"for each integer element in the input array".

If you did, that's good. You can map the words back to the symbols and you'll find that the ":" means "in the".

Most of the time, the simple answer is the right one.

marklawforda at 2007-7-13 12:47:14 > top of Java-index,Java Essentials,Java Programming...
# 2
is that an assumption?maybe i'm too adapted to the conventional way that for loop works.thanks! =)
geniver82a at 2007-7-13 12:47:14 > top of Java-index,Java Essentials,Java Programming...
# 3
FYI: This is the enhanced for loop that is new in JDK 1.5. You can read more about it from Sun's updated Java tutorial: http://java.sun.com/docs/books/tutorial/java/nutsandbolts/for.html
hungyee98a at 2007-7-13 12:47:14 > top of Java-index,Java Essentials,Java Programming...
# 4

> If a for loop looks like this, wha does the ' : " in

> the loop means?

This is really a hard question (seriously, no irony). This question is hard because it is like asking what the semi-colon ( ; ) means, when you declare variables, for example. There isn磘 an easy and satisfactory answer. The creators of Java language have just chosen colon to put inside for loop. It could be any other character. IMO, it would be much better if you didn磘 worry about it. Just accept the fact that you must use colon, in for loop. Or, if you really want to investigate the reason, you can study the java compiler, how the compiler works, the rules that the compiler follows in order to determine whether a code is well-written/valid, etc. I think doing it, you can know the meaning of ":".

TheLoosera at 2007-7-13 12:47:14 > top of Java-index,Java Essentials,Java Programming...
# 5
I think the easiest natural language reading of this (which is also, I think, what they use in the tutorial) reads the colon as "in".[code]for(Integer element : inputArray)[/code"For integer type variable 'element' in 'inputArray'".Drake
Drake_Duna at 2007-7-13 12:47:14 > top of Java-index,Java Essentials,Java Programming...