While

This is a discussion on While within the C++ Programming forums, part of the General Programming Boards category; Is there a way to check for more than one variable in a while statement like while (number1 == number2) ...

  1. #1
    Unregistered
    Guest

    While

    Is there a way to check for more than one
    variable in a while statement
    like
    while (number1 == number2)

    Ruffly put, that would check for 2 number being equal,,
    how could I add a 3rd, or a 4th or even a 5th number
    in that while statement?
    In other words a way to check for 5 number being the
    same.

    Thanks

    X

  2. #2
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    while (number1 == number2 && number1 == number 3)
    Last edited by Shadow; 08-02-2002 at 11:49 PM.
    The world is waiting. I must leave you now.

  3. #3
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    oooorrrrr

    while (vari1 == vari2 && vari1 == vari3 && vari1 == vari4)
    Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com

    -the shroom has spoken

  4. #4
    Unregistered
    Guest
    IC thanks..guys,but one question
    will thisl check if all the numbers are not equal to each other..
    or does it just see if the 1st number is not equal to the rest?

  5. #5
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    Write a for loop to test every possible comparison.

    [EDIT]
    BTW, this type of question should have answers all over the web.
    [/EDIT]
    Last edited by Shadow; 08-03-2002 at 12:57 AM.
    The world is waiting. I must leave you now.

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    362
    Shadow's right. Locating a "truth table" should be no problem at all, and should give you the insight needed to answer your question.

    A little snippet to get you started:

    'while ( x == y || y == z)' will pass the test even if y = 1 and z = 0 provided that x does, in fact, equal y.

    The use of the logical-OR (||) dictates that only one comparison evaluate to "true" in order to pass the test. Therefore, as soon as a "true" condition is encountered, the remainder are ignored, i.e. not even evaluated.

    You will really want to watch out for the logical-NOT (!) being thrown into the mix. You will have, at least, one conversation with yourself, I'm sure.

    -Skipper
    "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow

  7. #7
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by skipper
    Shadow's right. Locating a "truth table" should be no problem at all, and should give you the insight needed to answer your question.

    A little snippet to get you started:

    'while ( x == y || y == z)' will pass the test even if y = 1 and z = 0 provided that x does, in fact, equal y.

    The use of the logical-OR (||) dictates that only one comparison evaluate to "true" in order to pass the test. Therefore, as soon as a "true" condition is encountered, the remainder are ignored, i.e. not even evaluated.

    You will really want to watch out for the logical-NOT (!) being thrown into the mix. You will have, at least, one conversation with yourself, I'm sure.

    -Skipper
    reminds me of a colorful discussion i had with myself a few days ago about logical and vs bitwise and
    hello, internet!

Popular pages Recent additions subscribe to a feed

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