MrD
MrD

Reputation: 5086

Multiple conditions on for loop

I am writing a for loop as follows:

for(int i = row, int j = col; i < rows, j < cols; i++, j++)

However, it appears Java isn't liking it... Is there any way I can achive something similar?

Thanks!

Upvotes: 1

Views: 2406

Answers (3)

kaysush
kaysush

Reputation: 4836

for(int i = row,j = col; i < rows&& j < cols; i++, j++) you can't have multiple declarations in for loop and should have single boolean expression

Upvotes: 0

zibi
zibi

Reputation: 3313

The second expression needs to be a boolean expresion, so

i < rows, j < cols

is not a boolean. You could try

i < rows && j < cols

Upvotes: 1

Mike
Mike

Reputation: 2434

use &&. Also, int only once.

for(int i = row, j = col; i < rows && j < cols; i++, j++)

Upvotes: 6

Related Questions