1

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!

2
  • or(int i = row,j = col; i < rows, j < cols; i++, j++) you can't have multiple declarations in for loop Commented Jan 6, 2013 at 16:36
  • possible duplicate of Giving multiple conditions in for loop in Java Commented Jan 6, 2013 at 17:48

3 Answers 3

6

use &&. Also, int only once.

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

Sign up to request clarification or add additional context in comments.

2 Comments

@user1876047 If you are satisfied with the answer, then it's a good practice to accept it.
Note, This will not iterate of every cell, just the diagonal from a fixed point. I suspect this is not what you reall want.
1

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

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.