Math Wiki

Boolean logic in Programming Languages

667pages on
this wiki

For background to this topic see Boolean logic

Boolean logic is used in nearly every Programming Language. Computer programming is a major use of Boolean logic. It allows us to translate real world problems into computer code.

C, C++, and C#Edit

C, C++ and C# are three different computer programming languages that use very similar syntax. We can look at how Boolean logic is used in these languages however the and, or, and not operators are represented by different symbols to those used in mathematics.


Logical operatorsEdit

logical and & (also bitwise), && (short-circuit)
logical or | (also bitwise), || (short-circuit)
logical negation !

Comparison operatorsEdit

Operators that go well with logical operators are:

equal to ==
less than <
less than or equal to <=
greater than >
greater than or equal to >=
not equal to !=

Other operatorsEdit

ternary conditional ? :

If statementEdit

These logical operators are used to create logical statements by beginning the statement with if.

To test the values which are stored in two variables called A and B then:

if(A > 5 && B < 20)

If the statement is true then the program code continues on the following statement. If the logical statement is false then the code skips the next statement.

This statement is read as: if A is greater than 5 and B is less than 20 then process the following line.

Advertisement | Your ad here

Around Wikia's network

Random Wiki