Thread: Infinite Loops in C

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    48

    Infinite Loops in C

    How to make an infinite loop in C .If I am using while for example??

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Code:
    while (1) {
       printf("forever");
    }

  3. #3
    Registered User
    Join Date
    Jul 2008
    Posts
    48
    Thanks!

  4. #4
    Registered User
    Join Date
    Jul 2008
    Posts
    48
    That perfectly worked

  5. #5
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    Code:
    for(;;)
    {
        printf("Alternative infinite loop.\n");
    }

  6. #6
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Code:
    Loop:
       printf( "Infinite loop with goto." );
       goto Loop;

  7. #7
    Registered User
    Join Date
    Apr 2008
    Posts
    14
    I like doing it this way:

    Code:
    #define forever while(1)
    
    forever {
            printf("loop\n");
    }

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I like doing it this way:
    I do not think it is worth the trouble though. for (;;) and while (1) are universally recognised as deliberate infinite loops.
    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

  9. #9
    Registered User
    Join Date
    Jul 2008
    Posts
    48
    Thanks guys You are all great!! and so are your suggestions

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Infinite While Loops Question
    By hern in forum C++ Programming
    Replies: 4
    Last Post: 08-13-2005, 07:27 PM
  2. please help, infinite loops!
    By HybridM in forum C++ Programming
    Replies: 18
    Last Post: 01-14-2003, 09:27 PM
  3. i have infinite loops. why?
    By hermit in forum C Programming
    Replies: 20
    Last Post: 04-17-2002, 06:58 AM
  4. help with arrays and loops
    By jdiazj1 in forum C Programming
    Replies: 4
    Last Post: 11-24-2001, 04:28 PM