Thread: Infinite loop will not stop.

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    4

    Infinite loop will not stop.

    I recently made a Do-while loop in C++ with Code::Blocks while doing the tutorial about loops, and when I ran it, it would not stop. I have tried clicking X, stopping the task in Task Manager, and pressing ctrl+c, but none of these will work. The window will close, but the debugger will not stop running. When I try to run another program, it says: ld.exe||cannot open output file bin\Debug\File.exe Permission denied| ||=== Build finished: 1 errors, 0 warnings ===|. I deleted the code I had entered when I ran the loop, and do not remember it. I am new to programming and would welcome any help to fix this.

    Thanks.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Since you cannot reproduce the code, there is no help that can possibly be provided to fix the code

    You probably made some classic mistake like incrementing a loop counter with a loop condition that checks if the loop counter is greater than, rather than less than, some value.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Aug 2011
    Posts
    4
    I think it was similar to this:

    Code:
     #include <iostream>
    
    using namespace std;
    
    int main()
    {
      int x;
    
      x = 0;
      x++;
      do
      {
        cout<<"Hello, world!\n";
      }
      while ( x < 3 );
      cin.get();
    }

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Ah, then you forgot to increment the counter in the loop.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Aug 2011
    Posts
    4
    Is there any way I can just delete the whole program that is looping? I don't really need it and when I try to delete it, it says it is being used and won't let me.

  6. #6
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by Retribution View Post
    Is there any way I can just delete the whole program that is looping? I don't really need it and when I try to delete it, it says it is being used and won't let me.
    You want to delete the executable ...right? Just stop its running and then do so. If you're attempting to delete the source file, you need to close the ide. Also; why is your program still looping?,...didn't you follow the thread to correct it?

  7. #7
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    What do you mean? stop the program when it loops uncontrollably? you can use the CTRL+break / pause combo on your keyboard, also in the task manager look for other processes that are linked to the console or debugger and stop those, but the permission denied error is reported often so try this search
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  8. #8
    Registered User
    Join Date
    Aug 2011
    Posts
    4
    Ok I fixed it. I just deleted the executable in the processes section of task manager.

    Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. infinite loop
    By leahknowles in forum C Programming
    Replies: 4
    Last Post: 03-24-2011, 03:37 PM
  2. Replies: 8
    Last Post: 07-29-2010, 01:57 PM
  3. Replies: 2
    Last Post: 06-14-2009, 11:24 PM
  4. How to stop an infinite cyle?
    By opsis in forum Linux Programming
    Replies: 4
    Last Post: 01-07-2007, 12:58 PM
  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, 11:17 AM

Tags for this Thread