aspose file tools*
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 Soft Skills this week in the Jobs Discussion 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: 1732
    
  12

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: 1732
    
  12

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

Joined: Oct 25, 2008
Posts: 2700

You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Rule Round Up #30 - What?? for loop declarations