# Reading pins that are in a Matrix and storing the values into an array

I’ve been trying to use digitalRead to read a value of pins in an array then assign those values to a new array. I then try to add all the 1’s and 0’s in the array and test it against another value, but I read the values as 0’s on the serial monitor every time I run the code with current running through some of the pins. Not sure what I’m doing wrong.

``````void loop() {
Vector<int> blocks;
int B[grid];
int sum_of_blocks;
int C;

if(T == 1){
A = area[random(0,10)];
T = 0;
}else if(T == 0){

int j;
for(j=0; j= grid; j++){
};

int l;
for (int m=(sizeof(B)/sizeof(B[0])); m > 0; --m){ // Adds all elements in the blocks vector
sum_of_blocks += B[m-1];
};

C = sum_of_blocks;
if(C == A){ // Checks if block vector sum is == to random generated area to restart the program with a new A
T = 1;
lcd.clear();
}else{
T = 0;
}
}
``````

for(j=0; j= grid; j++){
Did you mean
for(j=0; j <= grid; j++){

Does that change the meaning of the coding?
The second parameter just tells the for loop when to stop and if “j” = grid then it should be the same if j<=grid. I’m new to coding in general so let me know if I’m wrong.

“The second parameter just tells the for loop when to stop ”
Does it?

If your condition is j= grid; how does the ‘for’ flow chart work?

If the condition is changed to j<= grid; how does the ‘for’ flow chart work differently?

‘for’ flow chart: