my dog learned polymorphism
The moose likes Beginning Java and the fly likes for loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "for loop" Watch "for loop" New topic

for loop

Vlada Den
Ranch Hand

Joined: Dec 19, 2004
Posts: 32

Is it possible to declare more than one variable in the initialization part of for loop?

If yes, could you post some code examples?


Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Chris Wox
Ranch Hand

Joined: May 25, 2006
Posts: 34
for (byte i = 1, j = 1; i < 10 , i++, j++);
{ System.out.println(i + ":" + j) ;

you can also increment both variables
[ May 26, 2006: Message edited by: Chris Wox ]
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
for loop
marc weber

Joined: Aug 31, 2004
Posts: 11343

Note that variables declared in a for loop must all be of the same type (i.e., as a single line of code).

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
I agree. Here's the link:
subject: for loop
It's not a secret anymore!