This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell 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


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: 1669
    
  11

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: 1669
    
  11

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

Joined: Oct 25, 2008
Posts: 2700

You're welcome
 
GeeCON Prague 2014
 
subject: Rule Round Up #30 - What?? for loop declarations