0% found this document useful (0 votes)
15 views

Boolean Expression

Boolean expressions in programming languages evaluate to true or false. They use relational operators like <, <=, >, >=, ==, != to compare values. Logical operators like AND (&&), OR (||), and NOT (!) can combine simpler Boolean expressions into more complex ones. The truth tables show the output of each logical operator combination. Boolean expressions are commonly used in if-else conditional statements to control program flow.

Uploaded by

jackhong05
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Boolean Expression

Boolean expressions in programming languages evaluate to true or false. They use relational operators like <, <=, >, >=, ==, != to compare values. Logical operators like AND (&&), OR (||), and NOT (!) can combine simpler Boolean expressions into more complex ones. The truth tables show the output of each logical operator combination. Boolean expressions are commonly used in if-else conditional statements to control program flow.

Uploaded by

jackhong05
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Boolean expression in programming language is an expression that results in a value either TRUE or FALSE.

It is using the relational operators to represented less than or greater than to identified the expression is TRUE or FALSE. Below is the table that shows the sign of relational operator. Relational operator < <= > >= == != For example, Given 4 < 10, This is a Boolean Expression because the result for the expression is TRUE where 4 is less than 10. In the program also can write: If (I < 10) { printf (The value is under limit); } Function Less than Less than or equal to Greater than Greater than or equal to Equal to Not equal to

For more complex Boolean expressions can be built out of simpler expressions, below is show the Logical Boolean operators: Logical Boolean operators && || Function AND OR Example Tall && Fat (The man is tall and fat) Hot || cold (Would you like hot or cold for a cup of coffee?) ! NOT ! danger ( Not danger)

a 0 (F) 0 (F) 1 (T) 1 (T)

b 0 (F) 1 (T) 0 (F) 1 (T)

a AND b 0 (F) 0 (F) 0 (F) 1 (T)

a OR b 0 (F) 1 (T) 1 (T) 1 (T)

NOT a 1 (T) 1 (T) 0 (F) 0 (F)

Boolean operator truth table: 1 = T (TRUE), 0 = F (FALSE) The && (AND) is an operator that produce a true result if both operand are true where the left-hand side is true and the right-hand side is true. This operation is same like multiply (*) function. Example in program: if (a==1 && b==1) { Printf (The system run); } Above program is show that the i value is between 2 until 19.

The || (OR) is an operator that produce a true result if either operand is true. This operation is same like add (+) function. Example in program:

if (a==0 || b==1) { Printf (The expression is TRUE); } Above program is show that the weight is less than 50 or weight more than 70 is fail on the weight test.

The ! (NOT) is an operator that takes a single true/false value and negates it where change false to true and true to false. Example in program: if (danger) { printf (Run faster); } else if (!danger) { printf (Cool down); }

Boolean expressions are also called as comparison expressions, conditional expressions, and relational expressions.

You might also like