This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Rule Round Up #30 - What?? for loop declarations Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Rule Round Up #30 - What?? for loop declarations" Watch "Rule Round Up #30 - What?? for loop declarations" New topic
Author

Rule Round Up #30 - What?? for loop declarations

Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1623
    
  10

Is this legal?
int i;
for (i = 4, int t = 6; i < 0; i++)

Answer: No.
You can declare or initialize more than one variable in a for loop, but you can't mix declarations with initializations.


What? It's telling me I can do it in the answer, but it's telling me that it's wrong.

So what does one look like that is correct?


When you do things right, people won't be sure you've done anything at all.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

They mean that you can declare and initialize multiple variables

And only initialize more variables:

But you can't mix it.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1623
    
  10

Ahh.... I get it now! Thanks, Wouter!
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

You're welcome
 
 
subject: Rule Round Up #30 - What?? for loop declarations
 
Similar Threads
Jxam Question?
What are Compiler time Constants?
Local variable
converting this to a prefix instead of a postfix calculator
Removing rows from a default table model