timing with for loops

i just recently made a program that used a for loop to delay a second ( well actually close to a second as i could quickly come) , but the only problem was i had to loop it about 240 million times per second. To me that seems a little redundant and using too many resources for such a simple task. Im not sure becuz i havent gotten to work with any <time> included files yet, so this is the closest ive came to controlling the timing.

is there a more simple, less resource using way???
Sleep(DWORD milliseconds) - windows only though :( (Window.h)
what about for linux?
Last edited on
Here are the first two links I got by googling sleep linux:

(1) http://linux.die.net/man/3/sleep (2) http://linux.die.net/man/3/usleep
thanks m4ster r0shi
@vlad: its <windows.h>

@metulburr:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <windows.h>
#include <iostream>
#include <conio.h>
using namespace std;

int main () {
	while (true) {
		Sleep (1000);
		for unsigned long i = 1; i <= 240000000; ++i) {
			//do something...
		}
		if (...)
			break;
	}
	cout << "the loop is over..." << endl;
	cout << "press any key to continue...";
	getch();
	return 0;
}
Topic archived. No new replies allowed.