Thread: Really really silly question

  1. #1
    Registered User
    Join Date
    Jan 2005

    Really really silly question

    I am kinda confused and I had to ask this. In a statement like
    while((x <= 10) && (y > 8) && (z != 0))
        do something
    The statements in the body of the while will NOT execute when any of the conditions is not true, right? Thanks and sorry

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    How about writing a test case and finding out for yourself?
    x = 11, y = 7, z = 1;
    if( (x <= 10) && (y > 8) && (z != 0) )
        printf("Is this what you expect?\n");

    Hope is the first step on the road to disappointment.

  3. #3
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    why not just try it?

    ... and yes, when they are not true, and perhaps even if they arn't not false.

  4. #4
    the c-dil
    Join Date
    May 2005

    Really really silly question

    yes, in a test condition , if we are checking for an AND operation
    if any condition gives false , the compiler won't check for any
    other condition and we will come out of the loop immediately.

    Similarly for an OR operation if any condition gives true , the
    compiler won't check for any of the remaining condition and will
    perform the required function
    Rajat kochhar

  5. #5
    Registered User
    Join Date
    Jun 2004
    a quick and important note:
    the cicle only break when the expression is evaluated, which happens at the beginning of every cicle.
    if somehow some of the variables on the expression change it's value, the cicle won't break, it'll continue normally until it restarts and re-avaluates the expression

  6. #6
    The C-er
    Join Date
    Mar 2004
    What's a cicle?

  7. #7
    Registered User
    Join Date
    Oct 2001
    >What's a cicle?
    cycle, where I believe cycle equates to loop.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Silly question but..
    By swgh in forum C++ Programming
    Replies: 3
    Last Post: 05-05-2008, 12:39 PM
  2. A silly question but it's my doubt ;)
    By chottachatri in forum C++ Programming
    Replies: 19
    Last Post: 04-23-2008, 01:26 PM
  3. Really quick silly question.
    By Jozrael in forum C++ Programming
    Replies: 36
    Last Post: 04-04-2008, 08:31 AM
  4. Question...
    By TechWins in forum A Brief History of
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM