1

ok, so this is in ActionScript 3, my problem is here:

var numCols:uint = 7;
numRows:uint = 7;

row = 1;
column = 3;

total = row+column-1    
for(i = 0; i < numRows; i++){
    for(j = 0; j < numCols; j++){
        if(j < column){
            array[i][j]=total--
        }else{
            array[i][j]=total++                     
        }
    }
}

I am expecting this result in array:

3,2,1,2,3,4....

However I get this:

3,2,1,0,1,2,3,4...
3
  • Unless you put the value of the 2-dimensional array, it's difficult to say where the problem is. Commented Nov 7, 2011 at 13:10
  • do you want to know the values before I try to run this code? Commented Nov 7, 2011 at 13:13
  • Yes, otherwise how should I know what the code fragment is supposed to do? Commented Nov 7, 2011 at 13:20

1 Answer 1

1

Problem

Your condition

if (j < column)

evaluates to true three times.

1. column = 3, j = 0, total = 3, total becomes 2
2. column = 3, j = 1, total = 2, total becomes 1
3. column = 3, j = 2, total = 1, total becomes 0

the fourth time, the else clause gets executed but by this time, your total has dropped to 0.

4. column = 3, j = 3, total = 0, total becomes 1.

Possible solution

I don't know your use case but changing

array[i][j]=total++   

to

array[i][j]=++total

could be all it takes.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.