help with MIDI patch

hi all, I am trying to build a MIDI keyboard with arduino. I have installed midi firmware and so on.
Every think seems to work, but I have a problem with the sketch. Now I am testing with 3 buttons, but finally I want to make it with 14.
So if I upload this sketch:

#include <MIDI.h>

const byte keys[] = {8, 9, 10};
const byte notes[] = {36, 38, 40};
const byte LED = 13;
 
boolean kPress[3];
boolean note[3];
 
void  setup() {
  for (byte set=0; keys[set]!=0; set++){
    pinMode(keys[set], INPUT);
  }
  pinMode(LED, OUTPUT);
  MIDI.begin();
}

void loop() {
  kPress[0] = digitalRead(keys[0]);
  if (kPress[0] == HIGH){ 
    digitalWrite(LED, HIGH); 
    if(!note[0]){ 
       MIDI.sendNoteOn(notes[0],127,1); 
       note[0] = HIGH;
    }
  }
  else{
    digitalWrite(LED,LOW); 
    if(note[0]){ 
      MIDI.sendNoteOff(notes[0],0,1); 
      note[0] = LOW; 
    }
  } 
  //-------------------------------
  kPress[1] = digitalRead(keys[1]); 
  if (kPress[1] == HIGH){ 
    digitalWrite(LED, HIGH); 
    if(!note[1]){ 
       MIDI.sendNoteOn(notes[1],127,1); 
       note[1] = HIGH;
    }
  }
  else{
    digitalWrite(LED,LOW); 
    if(note[1]){ 
      MIDI.sendNoteOff(notes[1],0,1); 
      note[1] = LOW; 
    }
  } 
  //------------------------------
  kPress[2] = digitalRead(keys[2]); 
  if (kPress[2] == HIGH){ 
    digitalWrite(LED, HIGH); 
    if(!note[2]){ 
       MIDI.sendNoteOn(notes[2],127,1); 
       note[2] = HIGH;
    }
  }
  else{
    digitalWrite(LED,LOW); 
    if(note[2]){ 
      MIDI.sendNoteOff(notes[2],0,1); 
      note[2] = LOW; 
    }
  } 
  delay(50);
}

everything works fine
if I try to make a shorter variant with a for loop:

#include <MIDI.h>

const byte keys[] = {8, 9, 10};
const byte notes[] = {36, 38, 40};
const byte LED = 13;
 
boolean kPress[sizeof(keys)] = {LOW};
boolean note[sizeof(notes)] = {LOW};
 
void  setup() {
  for (byte set=0; keys[set]!=0; set++){
    pinMode(keys[set], INPUT);
  }
  pinMode(LED, OUTPUT);
  MIDI.begin();
}

void loop() {
  for (byte i=0; keys[i]!=0; i++){
    kPress[i] = digitalRead(keys[i]);
    
    if (kPress[i] == HIGH){ 
      digitalWrite(LED, HIGH); 
      if(!note[i]){ 
         MIDI.sendNoteOn(notes[i],127,1); 
         note[i] = HIGH;
      }
    }
    else{
      digitalWrite(LED,LOW); 
      if(note[i]){ 
        MIDI.sendNoteOff(notes[i],0,1); 
        note[i] = LOW; 
      }
    } 
  }
  delay(100);
}

it glitches, I mean when I press the button it pushes sequence of notes fast one after another. If I follow the steps in the code everything looks the same as in the first patch. What is wrong?

I am new to programing and arduino, can anyone help?

Thanks in advance

what does keys equal when i=3?

Oh, :~ stupid!

Thanks a lot :slight_smile: !!!