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
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply 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: 1611
    
  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: 1611
    
  10

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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Rule Round Up #30 - What?? for loop declarations
 
Similar Threads
converting this to a prefix instead of a postfix calculator
Jxam Question?
What are Compiler time Constants?
Removing rows from a default table model
Local variable