From the function definition, foreveryou can see that it is a standard recursive function.
forever :: (Monad m) => m a -> m b
forever a = a >> forever a
There is no magic. foreveris only a recursive function. In your particular case, this does not end there. But whether it will be final or non-final depends on how Monad is defined for this type.
Inspect the type >>, we get:
λ> :t (>>)
(>>) :: Monad m => m a -> m b -> m b
, m a . , >> . m a IO (), putStrLn.
IO Monad, forever IO.