Not all code paths return a value error

I’ve been going through the book “Unity Game Development Blueprints” and have encountered an error in Chapter 1 that for the life of me, I cannot figure out. Could someone help me?

Here’s the function that is giving me trouble:

    /*
     * Will return if any of the keys are pressed,
     * otherwise it will return (0,0,0)
     */
    Vector3 MoveIfPressed( List<KeyCode> keyList, Vector3 Movement) {
        // Check each key in our list
        foreach (KeyCode element in keyList) {
            if (Input.GetKey(element)) {
                // It was pressed so we leave the function with the Movement applied
                return Movement;
            }
            // key not pressed
            return Vector3.zero;
        }
    }

The error I’m getting is “Assets/Scripts/PlayerBehaviour.cs(121,17): error CS0161: `PlayerBehaviour.MoveIfPressed(System.Collections.Generic.List<UnityEngine.KeyCode>, UnityEngine.Vector3)': not all code paths return a value”. I did a bit of digging online and it seems to me this error occurs if you have a path in your code that does not return a value. But I’m not seeing where that is. Do I need to have something returned after the foreach loop, even if if I shouldn’t ever hit that line?

move the return Vector3.zero; from the foreach to between line 14-15

Or, if you feed the function with a blank list, foreach won’t work and no return going to happen.

It works! Thank you!