Move the v calculation to the outer for loop. No reason to keep calculating the same value.

Stylistically I prefer double over num as its more specific.