Boolean

A Boolean type is declared with the bool keyword and can only take the values true or false. We use Booleans in programming to make comparisons and to control the flow of the program.

Example:

bool isReady = false;

Before giving examples with operators, we must learn the String Interpolation that gives us the ability to embed expressions within normal strings, you would use the following syntax:

void main(){

   var name = "Aziz";

   var age = 20;

   print("I am ${name} I am ${age} years old");

}




I am Aziz I am 20 years old



Comparison Operators:


void main() {

  var x = 10;

  var y = 15;

  print("x == y: ${x == y}");

  print("x != y: ${x != y}");

  print("x < y: ${x < y}");

  print("x > y: ${x > y}");

  print("x <= y ${x <= y}:");

  print("x >= y ${x >= y}:");

}





x == y : false
x != y : true
x < y : true
x > y : false
x <= y : true
x >= y : false

Logical Operators:


void main() {

  print((9 > 7) && (2 < 4));

  print((8 == 8) || (6 != 6));

  print(!(3 <= 1));

}





true
true
true




== Truth Table

x

==

y

Returns

true

==

true

true

true

==

false

false

false

==

true

false

false

==

false

true

AND Truth Table

x

&&

y

Returns

true

&&

true

true

true

&&

false

false

false

&&

true

false

false

&&

false

false

OR Truth Table

x

||

y

Returns

true

||

true

true

true

||

false

true

false

||

true

true

false

||

false

false

NOT Truth Table

!

x

Returns

!

true

false

!

false

true