# Jump height being affected by the duration of how long jump button is pressed

So I've been trying to implement a controlled jump the way the title proclaims to make the game easier to play and having the ability to make harder challenges in each level. I have noticed how there are already posts regarding this subject so I have read each individual post trying to implement it by myself. I do think I managed to come up with something good but it is not working properly (this script is placed inside the Players Update method):

timer += (float)gameTime.ElapsedGameTime.TotalSeconds;

InputManager.keys.IsKeyDown(Keys.Up) && InputManager.lastKeys.IsKeyUp(Keys.Up)) ||
(jumpTime < 0 && !isGrounded && !isJumping))
{
if (jumpTime < 0)
{
speed.Y = -jumpTime * speed.Y;
jumpTime += timer;
}

else if (isGrounded)
{
speed.Y = -8.5f;
jumpTime = 7.0f;
speed.Y = jumpTime * speed.Y;
isGrounded = false;
}
else if (!isJumping)
{
speed.Y = -8.5f;
jumpTime = -6.0f;
speed.Y = -jumpTime * speed.Y;
isJumping = true;
}

else if (jumpTime > 0)
{
speed.Y = jumpTime * speed.Y;
jumpTime -= timer;
}
}
else
{
jumpTime = 0;
}


Basically, the problem with it is the player jumps infinitely and never stops once the button is pressed. I would take a guess that the if-statement has some errors, but I could be wrong. Could I get some advice of what I've done wrong here exactly?

I want to mention too that it's going to be a double jump mechanic, where the double jump is also affected by the duration of how long the jump key is pressed.