Infinite loop

This is a discussion on Infinite loop within the C++ Programming forums, part of the General Programming Boards category; does an infinite loop suck up computing cycles, thus slow down program? thnx in advance. simplified code: ...... ..... for(; ...

  1. #1
    Registered User Spectrum48k's Avatar
    Join Date
    May 2002
    Posts
    66

    Infinite loop

    does an infinite loop suck up computing cycles, thus slow
    down program?
    thnx in advance.

    simplified code:

    ......
    .....
    for(;{
    do{
    ............
    .............
    .............
    }while(........)

  2. #2
    Registered User Spectrum48k's Avatar
    Join Date
    May 2002
    Posts
    66

    correction with no smiley ..(doh)

    this is what i ment ...


    for(;;)
    do{
    .
    .
    .
    .
    }while(...)
    its alive... its ALIVE... ITS...AL...IIIVE !!!!!!!!!

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    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.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    >> Depends whats going on inside your infinite loop.

    how about this?
    Code:
    while(TRUE)
    {
       malloc(10000);
    }

  5. #5
    Registered User Spectrum48k's Avatar
    Join Date
    May 2002
    Posts
    66
    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;
    _____________________________________________
    its alive... its ALIVE... ITS...AL...IIIVE !!!!!!!!!

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    @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
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  7. #7
    Registered User Spectrum48k's Avatar
    Join Date
    May 2002
    Posts
    66
    @hammer: why is this code amusing ?

    Code:
    while(TRUE)
    {
       malloc(10000);
    }
    its alive... its ALIVE... ITS...AL...IIIVE !!!!!!!!!

  8. #8
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Lookup the malloc() function in your manual
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  9. #9
    Registered User Spectrum48k's Avatar
    Join Date
    May 2002
    Posts
    66
    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 ..
    its alive... its ALIVE... ITS...AL...IIIVE !!!!!!!!!

  10. #10
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    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;
    _____________________________________________
    Why do you need a forever loop there? Why not just loop
    Code:
    while(choice != 'q')
    ?

    Oh, and use code tags.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 06-15-2009, 12:24 AM
  2. Cosine fucntion and infinite loop.
    By youareafever in forum C Programming
    Replies: 2
    Last Post: 11-07-2008, 04:45 AM
  3. Infinite Loop with GetAsyncKeyState
    By guitarist809 in forum Windows Programming
    Replies: 1
    Last Post: 04-18-2008, 01:09 PM
  4. Switch statement = infinite loop
    By Lucid003 in forum C++ Programming
    Replies: 10
    Last Post: 10-10-2005, 01:46 AM
  5. stays in loop, but it's not an infinite loop (C++)
    By Berticus in forum C++ Programming
    Replies: 8
    Last Post: 07-19-2005, 12:17 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21