Boolean Operators

I looked on this site and I searched it on google, but I can't find out how to actually use Boolean Operators. I know the symbols, such as ! means not, but I don't know how to make the function work. All I know is stuff like this: (3 != 2) // evaluates to true.

Can anyone tell me how or point me to a page that shows me how? I'm mostly just looking for a simple example, because I can easily see how to do it from examples. It can't be anything complex though, beyond a simple Boolean operator, because I'm not far in programming yet.

Thanks! :)
Last edited on
Here are a few in C++:

== test for equality, (This is not the same as = )
>= Greater than or equal too
<= Less than or equal too
> Greater than
< Less than
!= Not equal too



A couple examples:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
int a = 10;
int b = 21;

if(a == b)
{
  cout << "Equal too.\n";
}
else if(a > b)
{
  cout << "A is greater than B\n";
}
else if(a < b)
{
  cout << "A is less than B\n";
}
else if(a <= b)
{
  cout << "A is less than or equal too B\n";
}
else if(a >= b)
{
  cout << "A is greater than or equal to B\n";
}


In this case it the program executes the less than loop (Note the >= and <= statements will never get executed)

In a for statement:
1
2
3
4
for(int i = 0; i <= 10; ++i)
{
  cout << i << endl;
}


In the for loop i is initialized to 0 and then the loop is executed and i is incremented. Then if i is less than or equal too 10 the loop will execute again.


In Boolean, everything will be true or false.
Last edited on
Ah thanks so much!
Topic archived. No new replies allowed.