Page 1 of 2 12 LastLast
Results 1 to 15 of 29
  1. #1
    crushed's Avatar
    Join Date
    Oct 2009
    Gender
    male
    Location
    My name is Jay. k?
    Posts
    415
    Reputation
    10
    Thanks
    113
    My Mood
    Sneaky

    Boolean operators.

    So yeah, I haven't really posted in a while, due to me not really doing anything in C++ due to school. But picking up now once more. Anyways, I've just been starting, so yeah. I'm doing lessons from pretty much everywhere now, I learn something new from every other book, whether it be the first lesson.

    So yeah, I was reading the 2nd Lesson on Cprogramming.com and I got really confused at one part. ._.

    A. !( 1 || 0 ) ANSWER: 0
    B. !( 1 || 1 && 0 ) ANSWER: 0 (AND is evaluated before OR)
    C. !( ( 1 || 0 ) && 0 ) ANSWER: 1 (Parenthesis are useful)

    AND OR NOT. The three operators of Boolean. Can someone explain to me what they mean? Like I know that !=not ||=or &&=and.

    But I mean, how they are used, and if possible, can you give me an example in a code, cause it's much easier for me to understand. Also, since I don't want to repost another thread. The break statement is used to break loops, correct? And the continue statement skips to the next part of the code? ._.;

    Sorry if it sounds confusing, but yeah. I'm still not finished Basics due to school, but I have 2 weeks of in which I intend to cover most of the basics.

    Thanks to those help, and thank you for your time.

    EDIT: An example I tried was
    Code:
    int main()
    {
       int a=10;
       if (a != 20){
                cout <<"Hi. I'm failing basics.";
             }
       return 0;
    }
    I understand that example, because it basically means if a does not equal 20, print the following. But I mean, the other ones are confusing to me, mostly or as well as and.
    Last edited by crushed; 12-18-2009 at 11:42 PM.

  2. #2
    falzarex's Avatar
    Join Date
    Apr 2008
    Gender
    male
    Location
    here
    Posts
    417
    Reputation
    14
    Thanks
    145
    If you mess around with d3d alot ull find that boolean operators become easier to understand.
    Let's say I want to make chams and the stride is 32
    if(stride == 32){chams;}
    so this if statement only requires stride to be equal to 32 for it to activate

    however, if I have this:
    if(stride == 32 && startIndex == 0){chams;]
    it means that my chams will only work IF I have stride as 32 AND startindex as 0 AT THE SAME TIME

    what about:
    if(stride == 32 || stride == 40){chams;}
    this means that my chams will work if either my stride is 32 or my stride is 40 so if either condtion is present then chams will activate

  3. The Following 2 Users Say Thank You to falzarex For This Useful Post:

    crushed (12-19-2009),Hell_Demon (12-19-2009)

  4. #3
    Void's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Inline.
    Posts
    3,198
    Reputation
    205
    Thanks
    1,445
    My Mood
    Mellow
    Boolean operators are actually very useful. I can give you a quick example here.

    Code:
    int x = 10;
    (x == 10 || x == 20)
    I'm sure you can guess what that does. This evaluates to true if x is either equal to 10 or 20. I guess you can use "or" operator if you have 2 possible answers of some sort...

    Now for the "and" operator.

    Code:
    int x = 5;
    int y = 10;
    
    (x == 5 && y == 10)
    Now this evaluates to true because, well it's obvious, x does equal 5 and y equals 10.

    Code:
    (x == 6 && y == 10)
    This evaluates to false. Even though y equals 10, x doesn't equal 5. Adding the "Not" operator to this will evaluate to true.

    Code:
    !true = false
    !false = true
    That's pretty understandable right?

    Err.. if anyone sees something wrong just tell me, i'm like half asleep right now.

  5. The Following User Says Thank You to Void For This Useful Post:

    crushed (12-19-2009)

  6. #4
    crushed's Avatar
    Join Date
    Oct 2009
    Gender
    male
    Location
    My name is Jay. k?
    Posts
    415
    Reputation
    10
    Thanks
    113
    My Mood
    Sneaky
    Quote Originally Posted by Davidm44 View Post
    Boolean operators are actually very useful. I can give you a quick example here.

    Code:
    int x = 10;
    (x == 10 || x == 20)
    I'm sure you can guess what that does. This evaluates to true if x is either equal to 10 or 20. I guess you can use "or" operator if you have 2 possible answers of some sort...

    Now for the "and" operator.

    Code:
    int x = 5;
    int y = 10;
    
    (x == 5 && y == 10)
    Now this evaluates to true because, well it's obvious, x does equal 5 and y equals 10.

    Code:
    (x == 6 && y == 10)
    This evaluates to false. Even though y equals 10, x doesn't equal 5. Adding the "Not" operator to this will evaluate to true.

    Code:
    !true = false
    !false = true
    That's pretty understandable right?

    Err.. if anyone sees something wrong just tell me, i'm like half asleep right now.
    Okay, I understood everything you said. Last part, though. !true=false. Meaning not true is false, right?
    And Not false is true?

    I got confused @ that bit. ._.

    Quote Originally Posted by falzarex View Post
    If you mess around with d3d alot ull find that boolean operators become easier to understand.
    Let's say I want to make chams and the stride is 32
    if(stride == 32){chams;}
    so this if statement only requires stride to be equal to 32 for it to activate

    however, if I have this:
    if(stride == 32 && startIndex == 0){chams;]
    it means that my chams will only work IF I have stride as 32 AND startindex as 0 AT THE SAME TIME

    what about:
    if(stride == 32 || stride == 40){chams;}
    this means that my chams will work if either my stride is 32 or my stride is 40 so if either condtion is present then chams will activate
    Thanks for that example, it actually did help.

  7. #5
    Void's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Inline.
    Posts
    3,198
    Reputation
    205
    Thanks
    1,445
    My Mood
    Mellow
    Exactly..
    Also, you were right about break, it "breaks out" of a loop.

    Code:
    int x;
    while(1)
    {
          cin >> x;
          if(x == 2)
          {
                  break;
          }
    }
    Here, we have an infinite loop and it will keep asking the user for input. Everytime the user does not input the number 2, it will just loop over and over again. Once the user inputs 2, it will "break out" of the infinite loop and continue with whatever follows.

    As for continue, i'm not sure but I believe it does the opposite.

    Code:
    int x;
    int count = 0;
    while(1)
    {
         cin >> x;
         if(x == 2)
         {
               continue;
         }
         count++;
    }
    Another infinite loop here. This time everytime the user doesn't input 2 it will increment "count" by one. When the user does input 2. It will skip immediately perform another loop, skipping everything. "count" won't be incremented, it will ask for user input again without incrementing.

    Not too sure about continue here

  8. The Following User Says Thank You to Void For This Useful Post:

    crushed (12-19-2009)

  9. #6
    crushed's Avatar
    Join Date
    Oct 2009
    Gender
    male
    Location
    My name is Jay. k?
    Posts
    415
    Reputation
    10
    Thanks
    113
    My Mood
    Sneaky
    Quote Originally Posted by Davidm44 View Post
    Exactly..
    Also, you were right about break, it "breaks out" of a loop.

    Code:
    int x;
    while(1)
    {
          cin >> x;
          if(x == 2)
          {
                  break;
          }
    }
    Here, we have an infinite loop and it will keep asking the user for input. Everytime the user does not input the number 2, it will just loop over and over again. Once the user inputs 2, it will "break out" of the infinite loop and continue with whatever follows.

    As for continue, i'm not sure but I believe it does the opposite.

    Code:
    int x;
    int count = 0;
    while(1)
    {
         cin >> x;
         if(x == 2)
         {
               continue;
         }
         count++;
    }
    Another infinite loop here. This time everytime the user doesn't input 2 it will increment "count" by one. When the user does input 2. It will skip immediately perform another loop, skipping everything. "count" won't be incremented, it will ask for user input again without incrementing.

    Not too sure about continue here
    Got it, I understand break now, just needa look more up on continue. Maybe get a bit more into boolean operators as well. Thanks.

  10. #7
    Void's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Inline.
    Posts
    3,198
    Reputation
    205
    Thanks
    1,445
    My Mood
    Mellow
    I don't think I ever needed to use continue before.. .__.

  11. #8
    Matrix_NEO006's Avatar
    Join Date
    Feb 2008
    Gender
    male
    Posts
    240
    Reputation
    12
    Thanks
    33
    My Mood
    Lonely
    Code:
    if (x>10 && y<1)>>it means if both x and y statement can be true at the same time then return true.
    return true;
    Code:
    if (x>100||x=10) >> this means if either one of them is true return 1.
    return 1;

  12. #9
    lalakijilp's Avatar
    Join Date
    Jan 2008
    Gender
    male
    Posts
    310
    Reputation
    9
    Thanks
    53
    My Mood
    Blah
    non of the above examples uses a boolean...
    they are all examples of if and while statements

    a boolean is a datatype that can only have the value true or false

    true ==1
    false ==0

    example copied from a site:
    Code:
     
    #include <iostream> 
    using namespace std;  
     
    int main() { 
      bool b; 
     
      b = false; 
      cout <<  "b is " << b << endl; 
     
      b = true; 
      cout <<  "b is " << b << endl; 
     
      
      if(b)                               // control the if statement 
         cout <<  "This is executed.\n"; 
     
      b = false; 
      if(b) 
         cout <<  "This is not executed.\n"; 
     
      // outcome of a relational operator is a true/false value 
      cout <<  "10 > 9 is " << (10 > 9) << endl; 
     
      return 0; 
    }
    A. !( 1 || 0 ) ANSWER: 0
    B. !( 1 || 1 && 0 ) ANSWER: 0 (AND is evaluated before OR)
    C. !( ( 1 || 0 ) && 0 ) ANSWER: 1 (Parenthesis are useful)
    example A.

    you start with the or.
    1 or 0 = 1 inverted 0

    example B.

    1 or 1&&0
    1= 1
    1&&0 = 0

    so
    1 or 1&&0
    is 1 0r 0 = 1 inverted =0

    example C.

    ( 1 || 0 ) && 0
    always first between the brackets so...
    1 or 0 = 1
    1&& 0 = 0 inverted is 1
    Last edited by lalakijilp; 12-19-2009 at 03:25 AM.

  13. #10
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    Quote Originally Posted by Davidm44 View Post
    I don't think I ever needed to use continue before.. .__.
    Code:
    int GetBestTarget()
    {
        for(int i=0;i<playercount;i++)
        {
            if(!IsVisible(players[i]))
            {
                continue;
            }
            if(GetDist2D(players[i],myplayer)<bestdist)
            {
                besttarget=players[i];
                bestdist = GetDist2D(players[i],myplayer);
            }
        }
        return besttarget;
    }
    does the same as

    Code:
    int GetBestTarget()
    {
        for(int i=0;i<playercount;i++)
        {
            if(IsVisible(players[i])) //notice I removed the not operator(the !)
            {
                if(GetDist2D(players[i],myplayer)<bestdist)
                {
                    besttarget=players[i];
                    bestdist = GetDist2D(players[i],myplayer);
                }
            }
        }
        return besttarget;
    }
    edit: I prefer the first one, since it shows what is happening more clearly(if he is not visible, continue(skip), if he is visible go through the other codens
    Ah we-a blaze the fyah, make it bun dem!

  14. The Following 2 Users Say Thank You to Hell_Demon For This Useful Post:

    crushed (12-19-2009),Void (12-19-2009)

  15. #11
    zhaoyun333's Avatar
    Join Date
    Apr 2009
    Gender
    male
    Posts
    396
    Reputation
    11
    Thanks
    1,125
    Code:
    int main(void){
    
    int myDick = 69;
    int inYourPussy = 69;
    
    float myHand = 0.0;
    float onYourTits = 0.0;
    
    bool imHorny = false;
    
    if(myDick==inYourPussy||myHand==onYourTits||imHorny){
          cout<<"Your a fag"<<endl;
    }
    In the expression if(myDick==inYourPussy||myHand==onYourTits||imHorn y)

    myDick is equal to inYourPussy so it is true so that expression will now be evaluated as

    if(1||myHand==onYourTits||imHorny)

    myHand is also equal to onYourTits so the expression will now be evaluated as

    if(1||1||imHorny)

    and imHorny is false so the expression is

    if(1 || 1 || 0 )

    since || means OR it means if any one of them is true than the statement will be true

    and it will output "Your a fag"
    There are five possible operations for any army. If you can fight, fight; if you cannot fight, defend; if you cannot defend, flee; if you cannot flee, surrender; if you cannot surrender, die." - Sima Yi

  16. The Following User Says Thank You to zhaoyun333 For This Useful Post:

    crushed (12-19-2009)

  17. #12
    falzarex's Avatar
    Join Date
    Apr 2008
    Gender
    male
    Location
    here
    Posts
    417
    Reputation
    14
    Thanks
    145
    Nice analogies ;P

  18. #13
    ilovecookies's Avatar
    Join Date
    Oct 2009
    Gender
    male
    Location
    In the C++ Section
    Posts
    321
    Reputation
    10
    Thanks
    67
    My Mood
    Shocked
    Quote Originally Posted by lalakijilp View Post
    non of the above examples uses a boolean...
    they are all examples of if and while statements

    a boolean is a datatype that can only have the value true or false

    true ==1
    false ==0

    example copied from a site:
    Code:
     
    #include <iostream> 
    using namespace std;  
     
    int main() { 
      bool b; 
     
      b = false; 
      cout <<  "b is " << b << endl; 
     
      b = true; 
      cout <<  "b is " << b << endl; 
     
      
      if(b)                               // control the if statement 
         cout <<  "This is executed.\n"; 
     
      b = false; 
      if(b) 
         cout <<  "This is not executed.\n"; 
     
      // outcome of a relational operator is a true/false value 
      cout <<  "10 > 9 is " << (10 > 9) << endl; 
     
      return 0; 
    }


    example A.

    you start with the or.
    1 or 0 = 1 inverted 0

    example B.

    1 or 1&&0
    1= 1
    1&&0 = 0

    so
    1 or 1&&0
    is 1 0r 0 = 1 inverted =0

    example C.

    ( 1 || 0 ) && 0
    always first between the brackets so...
    1 or 0 = 1
    1&& 0 = 0 inverted is 1

    You're not wrong, boolean does return true or false, true being 1, false being anything but 1. AJ is asking about the boolean OPERATORS I believe. The operators being !, && and ||. != Not, && = And, || = Or.

    Now you go through an analyze how each works.

    I'll start with the operator which is evaluated first.

    && is the first boolean operator to be evaluated if there is more than one operator present. It compares two values, if either value is false, then the whole && comparison is false, i.e. 1 && 0 would return false because one of the values is false. 1&&1 would return true because both values are true.

    || is evaluated second after &&, || compares 2 values just like &&. If either value compared is true, then the whole || comparison is true, i.e. 1 || 0 evaluates to true because one of the statements is true. 0 || 0 returns false, because neither value is true.

    ! is to be evaluated lastly and is most likely outside of the parenthesis containing the other boolean operators. Whatever the value is found within the other comparisons, would be reversed. IE. !(1||0), 1||0 will return true, because one of the values is true. But the ! operator outside of the statement reverses that making the statement false. So !(1||0) will return false.

    Parenthesis are useful aswell, because the operators must be evaluated in a certain order, you can modify that order through parenthesis. IE

    !(1||0) &&0). Normally you would evaluate the && operator first, but because 1||0 are inside parenthesis before that, you will evalue that first. So 1||0 evaluates to True, because one of the values is true. Then you evaluate that value with the && operator so the problem would look like this at this point.
    !(1&&0). Now we will evaluat 1&&0 since you evaluate && before !. 1&&0 evaluates to false, because one of the values is false. So we would now have this.
    !(0) And now lastly we evaluate the ! operator. So of course, if the answer is NOT 0, then it is of course 1, or true.

    =D Hope I helped ya.

    BTW fags, don't call me a C+P'er, google it. =) Hand typed.
    Quote Originally Posted by Jules Winnfield View Post
    I am the tyranny of evil men, and you are all the weak. But i'm trying Ringo,i'm trying real hard, to become the shepherd.
    excuse me miss, would you kindly reflect some photons off the epidermis covering your sternum directly into the camera iris or vacate the proximity immediately
    [IMG]https://i882.photobucke*****m/albums/ac23/miki_d420/RealizingYoureALeecher2copy.jpg[/IMG]









  19. The Following User Says Thank You to ilovecookies For This Useful Post:

    crushed (12-19-2009)

  20. #14
    crushed's Avatar
    Join Date
    Oct 2009
    Gender
    male
    Location
    My name is Jay. k?
    Posts
    415
    Reputation
    10
    Thanks
    113
    My Mood
    Sneaky
    Thanks a ton guys! LOL. Nice examples
    And COOKIES, HOW DARE YOU TELL THEM MY NAME?
    Nah, I'm JP. But thanks alot man, I understood exactly what you said. :P

  21. #15
    zhaoyun333's Avatar
    Join Date
    Apr 2009
    Gender
    male
    Posts
    396
    Reputation
    11
    Thanks
    1,125
    Errr actually cookies is wrong, everything other than 1 is true. bool n = (36) in this expression n is true

    !(1||0) &&0) <--- your missing a bracket....but i suppose it would be here
    !((1||0) &&0)
    Since the INSIDE brackets are first we evaluate (1||0) which is true
    !( 1 && 0 )
    both have to be true so this express is now
    ! (0)
    the ! operator flips the bit so it would be
    1
    There are five possible operations for any army. If you can fight, fight; if you cannot fight, defend; if you cannot defend, flee; if you cannot flee, surrender; if you cannot surrender, die." - Sima Yi

Page 1 of 2 12 LastLast

Similar Threads

  1. d.vel.oper
    By Jeckels in forum WarRock - International Hacks
    Replies: 14
    Last Post: 10-16-2007, 01:53 PM
  2. Operation Northwoods
    By Grim09 in forum General
    Replies: 12
    Last Post: 07-21-2007, 12:45 AM
  3. [RELEASE] Operation Kcah V1.0
    By ArtofLife in forum WarRock - International Hacks
    Replies: 19
    Last Post: 06-09-2007, 03:34 PM
  4. Dont Sample The Boolean
    By kvmn8 in forum General
    Replies: 3
    Last Post: 06-15-2006, 08:48 AM