Boolean in go lang


Boolean (named on gorge bool) is a special 1 bit value which represents true or false.
  1. In Go lang, true and false are two reserved literals which represent Boolean values.
  2. Like some other programming language C, C++, go doesn't allow 1 at the place of true and 0 at the place of 0.
  3. Boolean values can be combined with logical operators. List of the logical operators is given below.
&& AND
|| OR
! NOT

Logical operators

  1. && (AND) and || (OR) operators are used to combine two or more Boolean values/expressions.
  2. ! (Not) operator also called negation, just reverse the Boolean values.
    1. !true results false
    2. !false results true
  3. && (AND) operator returns true if all the conditions are true.
  4. || (OR) operator returns true if any one condition is true.
  5. The outcome of the combination will be based on the following truth table.

Truth table for && (AND) and || (OR) operator

C1 C2 C1 && C2 C1 || C2
false false false false
false true false true
true false false true
true true true true

Example-1:

func main() { 
                 fmt.Println(true && true) 
                 fmt.Println(true && false) 
                 fmt.Println(true || true) 
                 fmt.Println(true || false) 
                 fmt.Println(!true)
}

Output

true
false
true
true
false

Comments

Popular posts from this blog

Overview of Go lang

Arrays in C Language

String in golang

Data Types in Go language

Creating your first html page

Say Hello world in Go lang

Installing go lang

Arrays in Go lang

Decision Making in Go lang

Decision Making Statements