If you are going to loop during the same tick until the key is released, it never gets a chance to check for the button being released because the loop will go as many times as possible before the next tick where it would check for the button release.
So instead of looping just do it once per timer event or per tick unless the button has been released which you can check on by setting a boolean variable on the press and release events. If you need to cycle through an array over time, keep track of the array index with a separate Integer varisble and increment it once per timer event or tick
This will make it act like a loop but happen over time i stead of all at once.
Im trying to detect if a key has been
pressed. If its been pressed repeat
loop until its not pressed.
There might be a much simpler solution that does not involve ticking or loops at all - an event based one. It all depends on what you’re trying to achieve, though.
Consider sharing more details to receive a more precise answer.