Home > Enterprise >  How to alter Boolean value from true to false and vice-versa in go-lang?
How to alter Boolean value from true to false and vice-versa in go-lang?

Time:11-11

I am new to golang and I have a requirement in golang of altering the bool value and store it. I am receiving value == true but i need to alter it and store the altered value. I can think of only storing the alerted to a var and pass it in the next statement.

Eg psuedo code :

chnagevalue := false

if value == false {
     changevalue == true 
}

what's the best way to do it in golang ? is there any pre-defined way to do it ?

TIA.

CodePudding user response:

Use the logical NOT operator ! to change true to false and vice versa:

changedValue := !value
  • Related