does an infinite loop suck up computing cycles, thus slow
down program?
thnx in advance.
simplified code:
......
.....
for(;;){
do{
............
.............
.............
}while(........)
Printable View
does an infinite loop suck up computing cycles, thus slow
down program?
thnx in advance.
simplified code:
......
.....
for(;;){
do{
............
.............
.............
}while(........)
this is what i ment ...
for(;;)
do{
.
.
.
.
}while(...)
If you make a mistake in your post, use the edit button, not reply.
>does an infinite loop suck up computing cycles,
Depends whats going on inside your infinite loop.
>> Depends whats going on inside your infinite loop.
how about this?Code:while(TRUE)
{
malloc(10000);
}
its just to repeat a menu.
example:
code:
___________________________________________
for(;;){
do{
cout << "Help on:\n";
cout << " 1. if\n";
cout << " 2. switch\n";
cout << " 3. for\n";
cout << " 4. while\n";
cout << " 5. do-while\n";
cout << " 6. break\n";
cout << " 7. continue\n";
cout << " 8. goto\n";
cout << "Choose one (q to quit): ";
cin >> choice;
}while(choice < '1' || choice > '8' && choice != 'q');
if(choice == 'q') break;
_____________________________________________
@Spectrum48k: Your program is going to spend most of its time waiting for the user to input something, which won't hog the CPU.
@ face_master: Err... yeah... let me try that one :D
@hammer: why is this code amusing ?
Code:
while(TRUE)
{
malloc(10000);
}
Lookup the malloc() function in your manual ;)
it allocates memory continusly untill i get:
"system low on virtual memory"
now i know.. sometimes i just ask, even though the books are next to me.. sorry bout that ..
Why do you need a forever loop there? Why not just loopQuote:
Originally posted by Spectrum48k
its just to repeat a menu.
example:
code:
___________________________________________
_____________________________________________Code:for(;;){
do{
cout << "Help on:\n";
cout << " 1. if\n";
cout << " 2. switch\n";
cout << " 3. for\n";
cout << " 4. while\n";
cout << " 5. do-while\n";
cout << " 6. break\n";
cout << " 7. continue\n";
cout << " 8. goto\n";
cout << "Choose one (q to quit): ";
cin >> choice;
}while(choice < '1' || choice > '8' && choice != 'q');
if(choice == 'q') break;
?Code:while(choice != 'q')
Oh, and use code tags.