Thread: c++ condition use? how u use it? help

  1. #1
    Registered User mikeasianlee's Avatar
    Join Date
    Nov 2004

    c++ condition use? how u use it? help

    how do u use the conditions, like if u want a program to locate a file, it will say file found and if not there, it will say not found?


  2. #2
    Registered User jimboob's Avatar
    Join Date
    Jun 2004
    It depends on the function.

    For example:

    bool Init();

    if (!Init)

    The exclamation means if init returns zero: then do something.

    Heres some more:

    && e.g: if (init && unit)
    which means if init and unit are true:

    || e.g: if (init || unit)
    which means if either init or unit is true:
    Last edited by jimboob; 12-06-2004 at 12:55 AM. Reason: Accidently pressed on submit after not realising tab didn't work

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    You have to CALL the function, jimboob.

    There are four statements that have a condition, if, while, do...while and for

    do ... while(condition)
    for( ; condition ; )

    The condition is just any kind of expression that can be converted to the bool type, which is a single boolean value (true/false logic). This means it may be directly a bool (bool variable, bool function return value, result of the comparison and logical operators <, >, <=, >=, ==, !=, &&, ||, !) or something convertible. All numbers (floats and integers alike) can be converted to bool using a simple rule: non-zero is true, zero is false. Pointers can be converted to bool, too. Non-null is true, null is false. You can define boolean conversions for your classes yourself.

    The comparison operators work just like you'd expect them to. > is greater-than, < is less-than. >= is greater-than-or-equal-to, <= less-than-or-equal-to. == is equal-to and != is not-equal-to.

    The logical operators are simple, too. && is logical AND, both sides must be true in order for the whole to be true. || is logical OR, both sides must be false in order for the whole to be false. ! is logical NOT, it flips the operand.
    && and || are lazy. They evaluate the right-hand-side only if it is required to determine the result. In (a && b), if a is false, then b is never evaluated. Similarly, in (a || b), if a is true, then b is never evaluated.
    All the buzzt!

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    Registered User mikeasianlee's Avatar
    Join Date
    Nov 2004
    can u guys give an example plz, how how to copy a file?

  5. #5
    Super Moderator
    Join Date
    Sep 2001
    I doubt you will find someone willing to write up some code in this manner. You will more than likely find a similar example in some of the C/ C++ tutorials on the web. There's a nice set of tutorials right here at (link on the main page), and you'll surely be able to find hundreds more at Google. Right now however, the tutorials on this site should be sufficient for your needs - give them a try.


    WARNING - The last time I visited this page my PC was temporarily paralyzed by well over a hundred pop-up ads. I'm not sure if this is more than a once-off problem, but I would definately open this link in a browser enabled with Pop-Up Blocker if convenient to avoid any potential hassle.

    Nevertheless, here's a link to this site's tutorial page.
    Last edited by sean; 12-06-2004 at 09:48 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. condition variable on read/write locks
    By ShwangShwing in forum C Programming
    Replies: 3
    Last Post: 04-29-2009, 09:32 AM
  2. Condition variables
    By sethjackson in forum Windows Programming
    Replies: 16
    Last Post: 03-19-2008, 11:42 AM
  3. SDL Condition variables.
    By antex in forum Game Programming
    Replies: 3
    Last Post: 11-11-2005, 07:11 AM
  4. Looping condition
    By Chaplin27 in forum C++ Programming
    Replies: 3
    Last Post: 05-29-2005, 02:06 PM
  5. Race condition
    By Roaring_Tiger in forum C Programming
    Replies: 5
    Last Post: 10-24-2004, 09:42 PM