Check if num is within range *before* accessing the array.