Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Janeice DelVecchio
Saloon Keeper
Posts: 1807
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They mean that you can declare and initialize multiple variables

And only initialize more variables:

But you can't mix it.
 
Janeice DelVecchio
Saloon Keeper
Posts: 1807
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahh.... I get it now! Thanks, Wouter!
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic