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);
}
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);
}
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.
> 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 ":".