While loop in C

What is the class called when you are doing a while loop.
it cant be public void. is there another way then to do a while loop if i want to make a charging attack?

private void CalculateCharge() {
		while if(Input.GetButtonDown("Attack"))
			chargeLevel += Time.deltaTime * chargeSpeed;
                     yield return null;
		}

This is a coroutine, thus must return type IEnumerator (don’t ask me what the hell is IEnumerator):

IEnumerator CalculateCharge(){
    while (Input.GetButton("Attack")){
        chargeLevel += Time.deltaTime * chargeSpeed;
        yield return null;
    }
}

You must call it in C# with StartCoroutine(CalculateCharge()), or in another coroutine with yield return new CalculateCharge()

Notice also that while loops must be written this way:

while (condition){
  // code
}

In this case, condition is Input.GetButton(“buttonName”), because it must return true while the button is pressed (GetButtonDown returns true only during the update cycle).

The problem here is the return. A void() never returns anything. If you just remove that line it should work.