This all depends on what language you're using. I do it highly inefficiently: I store the current system time in a variable. Then I add the time to it that I want it to loop for (say, 5 seconds). Then I do a while loop (while the system time is less than the variable that holds the altered time). Inside the loop, there's no code, but it'll still loop for 5 seconds.
I know there are much more efficient ways to do it (there are Timer APIs, I think), but that way has worked for me.