While Loop Infinite... Rookie Mistake

You know, this is a rookie mistake. But, swallowing my pride… please help. The while loop I put in is looping infinitely.

I originally wanted it to be…
while (movement buttons are pressed){
allow for sprinting;
change boolean “sprintable” to TRUE;
}

So… this is just a question; should I have made this an IF statement instead of a while? I’ll test that to make sure as well. However, I want to know if it would work.

`#pragma strict
private var sprintable : boolean;

function Start () {
	
}

function Update () {
	// Initiates the sprintable boolean, if movement buttons are pressed down. If these are pressed, the user is
	// able to increase their speed by pressing shift alongside it.
	// currently creates an infinite loop...
	while(Input.GetKeyDown("w") || Input.GetKeyDown("a") || Input.GetKeyDown("s") || Input.GetKeyDown("d")){
		sprintable = true;
		Debug.Log('You are moving!');
	}
}`

Thanks in advance.

Try this :

#pragma strict

private var sprintable : boolean;

function Start () {

}

function Update () {
	// Initiates the sprintable boolean, if movement buttons are pressed down. If these are pressed, the user is
	// able to increase their speed by pressing shift alongside it. 
	// currently creates an infinite loop...
	if (Input.GetKey("w") || Input.GetKey("a") || Input.GetKey("s") || Input.GetKey("d"))
	{
		sprintable = true;
		Debug.Log('You are moving!');
	}
}

You also may use KeyCode.

To handle movement, you rarely need a “while” loop because the Update method is called at every frame.

EDIT : new code for several buttons (not tested) :

#pragma strict
    
private var sprintable : boolean;
    
function Start () {
    
}
    
function Update () {    
    if (Input.GetKey("w") || Input.GetKey("a") || Input.GetKey("s") || Input.GetKey("d"))
    {
        Debug.Log('You are moving!');
        if (Input.GetKey("e"))
        {
            sprintable = true;
            Debug.Log('And sprinting!');
        }
    }
}