If you haven't already tried it like you should have, yes it will.
At the end of the function, %num is deleted. Its value is lost. When the function is ran again, %num has no value because it hasn't been defined. Transferring this to a global variable will prevent it from being deleted at the end of the function, and will allow you to access it when the function is called again. This persistent variable is said to be in the global scope while your original implementation was confined to the local scope.