Thread: Infinite loop syntax question

  1. #16
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by CommonTater View Post
    One question... why?

    If you use either of those and get it to work (it will...) whatever your program is doing is going to come to a grinding halt with 100% CPU usage and no way out of the loop except by externally interrupting the program. These are things programmers generally avoid like the plague... So forgive my curiosity as to why you need to do this...
    It is rather common in embedded code to have an endless loop at the end of small test programs.

    Note: to OP I am trying to write my embedded code so I can test it with normal C compilers to verify simple unit tests. But, I am my own test team. It seems much easier/faster to test the code on a normal PC than on a micro-controller. I still have to test on the micro-controller; but, it reduces the problems found at that point.

    Tim S.

  2. #17
    Princess of code universe programmer1's Avatar
    Join Date
    Nov 2011
    Location
    Wonderland
    Posts
    38
    Code:
    While(1)
    {}
    It should be like this. Because after while you can not use ";". At least I know that so.

  3. #18
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by programmer1 View Post
    Code:
    While(1)
    {}
    It should be like this. Because after while you can not use ";". At least I know that so.
    You are wrong; but, many people do it that way because it means it was on purpose instead of an accident ";".

    Tim S.

  4. #19
    Princess of code universe programmer1's Avatar
    Join Date
    Nov 2011
    Location
    Wonderland
    Posts
    38
    Quote Originally Posted by stahta01 View Post
    You are wrong; but, many people do it that way because it means it was on purpose instead of an accident ";".

    Tim S.
    Really? ı didn t know this. Thanks.

  5. #20
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Consider this code...
    Code:
    while (getchar() != '\n');
    Which is commonly used to empty the keyboard buffer between inputs.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 10-14-2011, 11:33 PM
  2. Beginner question: infinite loop
    By c++urious in forum C++ Programming
    Replies: 5
    Last Post: 12-12-2010, 03:07 AM
  3. 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
  4. infinite loop !
    By black in forum C++ Programming
    Replies: 7
    Last Post: 10-07-2002, 08:14 PM
  5. question ab an infinite loop...
    By JohnMayer in forum C Programming
    Replies: 10
    Last Post: 07-26-2002, 10:15 AM