# Assigning Arrays wont work (solved)

Hi!

Got a problem, and I don't know the cause >.<

I want to assign all numbers from one equally sized array to another. So far so easy, here the code I want to use that won't work, I don't get any output from the Serial port... not even the first gibberish line:

``````int Qarray[36] = {
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
};

int Rarray[36] = {
9,8,7,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
};

int z;

void setup(){

Serial.begin(9600);
}

void loop(){

for (z = 0; z = 35; z++){
Qarray[z] = Rarray[z];
}

Serial.println(Qarray[1]);

}
``````

If I'm assigning it like this everything works:

``````Qarray[1] = Rarray[1];
Qarray[2] = Rarray[2];
....
``````

Regards, Jazzar

edit: ok z should only run to 35 since the size of the array is 36 but last digit is number 35, anyway didn't help the least :-(

try:

void loop(){ for (z = 0; z < 36; z++){ Qarray[z] = Rarray[z]; }

Wow! Thanks a lot mem!

It works!

Any suggestion why? (since it should be the same) (just for curiosity)

Best regards, Jazzar

for loops repeat until the middle expression becomes false (zero)

the middle expression of your for loop was: z = 35; this sets the variable z to 35. The value of this expression never goes to zero and the loop never exits so your Serial.print code is never executed

z < 36 will be true (non-zero) for all values of z from 0 to 35 so the loop will repeat for each element in the array and stop when z is not less than 36.

Ah thanks!

Somehow got it mixed up... repeat until z equals 35 >.<