Really really silly question

This is a discussion on Really really silly question within the C Programming forums, part of the General Programming Boards category; I am kinda confused and I had to ask this. In a statement like Code: while((x <= 10) && (y ...

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    204

    Really really silly question

    I am kinda confused and I had to ask this. In a statement like
    Code:
    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
    Posts
    14,826
    How about writing a test case and finding out for yourself?
    Code:
    x = 11, y = 7, z = 1;
    
    if( (x <= 10) && (y > 8) && (z != 0) )
        printf("Is this what you expect?\n");

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    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
    Jun 2005
    Posts
    12

    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
    Posts
    722
    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
    Jez
    Jez is offline
    The C-er
    Join Date
    Mar 2004
    Posts
    192
    What's a cicle?

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >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, 01:39 PM
  2. A silly question but it's my doubt ;)
    By chottachatri in forum C++ Programming
    Replies: 19
    Last Post: 04-23-2008, 02:26 PM
  3. Really quick silly question.
    By Jozrael in forum C++ Programming
    Replies: 36
    Last Post: 04-04-2008, 09:31 AM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 10:47 PM
  5. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM

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