It doesn't wait forever... it runs. The problem is that it won't produce an output until the entire loop is done processing. Here's an example of how to overcome that printing problem... the details are in the comments... read 'em... :D
Code:
--===== How to force messages to screen on long running queries
--=========================================================================
-- What normally happens is there is no display until the end of run
--=========================================================================
PRINT 1
WAITFOR DELAY '00:00:5'
PRINT 1.5
WAITFOR DELAY '00:00:5'
PRINT 2
WAITFOR DELAY '00:00:5'
PRINT 3
GO
--=========================================================================
-- Raiserror forces the messages to be flushed as the run proceeds
--=========================================================================
PRINT 1
--======= Flush message 1 to client
RAISERROR ('After 1',10,1) WITH NOWAIT
WAITFOR DELAY '00:00:5'
PRINT 1.5
WAITFOR DELAY '00:00:5'
PRINT 2
--======= Flush waiting message(s) to client
-- This will send 1.5 and 2 to the client
RAISERROR ('After 2',10,1) WITH NOWAIT
WAITFOR DELAY '00:00:5'
PRINT 3
--===== Flush message 3 to client
RAISERROR ('After 3',10,1) WITH NOWAIT
--Jeff Moden