What are empty conditions

This is a discussion on What are empty conditions within the C Programming forums, part of the General Programming Boards category; I've looked around and I cannot seem to figure out what exactly this statement means: "However, an empty condition is ...

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    3

    What are empty conditions

    I've looked around and I cannot seem to figure out what exactly this statement means: "However, an empty condition is not legal for a while loop as it is with a for loop."

    I've even tried reading through a while and for statements section in a Java book to see if it would have a better explanation, no dice. Help is appreciated.

    At first I thought it was something like "while ();" or "for ();". But neither of those were accepted in my compiler.

    Thanks in advance,
    FLaTLiN3D

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,628
    Basically, this is legal:
    Code:
    unsigned int i;
    for (i = 0;; ++i);
    But this is not:
    Code:
    while ();
    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
    Sep 2010
    Posts
    3
    Quote Originally Posted by laserlight View Post
    Basically, this is legal:
    Code:
    unsigned int i;
    for (i = 0;; ++i);
    But this is not:
    Code:
    while ();
    How is the first one an empty condition though?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,628
    Quote Originally Posted by FLaTLiN3D
    How is the first one an empty condition though?
    Well, how many times will that for loop 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
    Sep 2010
    Posts
    3
    Quote Originally Posted by laserlight View Post
    Well, how many times will that for loop loop?
    Ehh... None? Because "i" can't be 0 and still be increasing by one, correct?
    I'm just getting started with C, and I'm not familiar with the double semi-colon that you used, what precisely does that to?

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,628
    Quote Originally Posted by FLaTLiN3D
    I'm not familiar with the double semi-colon that you used, what precisely does that to?
    Well, suppose I wrote this:
    Code:
    for (i = 0; i < 10; ++i);
    Looks more familiar? Now, remove the " i < 10". What do you get?

    So, that is the part that is the condition.
    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

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    33,292
    The forever loop is typically written as
    Code:
    for ( ; ; ) {
      // always
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can anyone help?
    By javalurnin in forum C Programming
    Replies: 11
    Last Post: 12-02-2009, 05:02 AM
  2. Help with binary file c++
    By lucky_mutani in forum C++ Programming
    Replies: 4
    Last Post: 06-05-2009, 09:24 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. skipping empty files using ifstream
    By bradleym83 in forum C++ Programming
    Replies: 14
    Last Post: 08-12-2005, 07:15 AM
  5. compiler build error
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 11-30-2003, 09:16 AM

Tags for this Thread


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