!my_bool vs bool=false

This is a discussion on !my_bool vs bool=false within the C++ Programming forums, part of the General Programming Boards category; I was under the impression that Code: !my_bool; would change my_bool from true to false or false to true... does ...

  1. #1
    Registered User QuestionKing's Avatar
    Join Date
    Jan 2009
    Posts
    68

    !my_bool vs bool=false

    I was under the impression that
    Code:
     !my_bool;
    would change my_bool from true to false or false to true... does it not work this way?
    Asking a question you already know the answer to might teach you something you did not know...

  2. #2
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    478
    Quote Originally Posted by QuestionKing View Post
    I was under the impression that
    Code:
     !my_bool;
    would change my_bool from true to false or false to true... does it not work this way?
    Code:
    !aBool;
    Does nothing.

    Code:
    bool foo = true;
    
    foo = !foo; // foo is false
    foo = !foo; // foo is true
    "What's up, Doc?"
    "'Up' is a relative concept. It has no intrinsic value."

  3. #3
    Registered User QuestionKing's Avatar
    Join Date
    Jan 2009
    Posts
    68
    I guess I should have included more code:
    Code:
    bool my_bool = true;
    do
      {
         //... if, else if,...
         else
         {
             my_bool = !my_bool;
         }
      }while(my_bool);
    ...but it appears I had a different problem, which I found. tyvm for the reply
    Asking a question you already know the answer to might teach you something you did not know...

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