Can someone please help me break down the following examples so they are easier to understand because I don't understand them at all. Many thanks in advance

Evaluate the following:
1) (true && true) || false
2) (false && true) || true
3) (false && true) || false || true
4) (5 > 6 || 4 > 3) && (7 > 8)
5) !(7 > 6 || 3 > 4)

1) (true && true) || false
2) (false && true) || true
3) (false && true) || false || true
4) (5 > 6 || 4 > 3) && (7 > 8)
5) !(7 > 6 || 3 > 4)

Assuming A is first term evaluation, B is second, and C is third (etc), then look at it this way (remember, multiple terms inside the parens are evaluated together so that the entire expression generates a result).

1) if both (A is true AND B is true) OR if C is false, then exprn == true
2) if both (A is false AND B is true) OR if C is true, then exprn == true
3) if both (A is false AND B is true) OR if C false OR if D is true, then exprn == true
4) if either (5 > 6 OR 4 > 3) AND (7 > 8), then exprn == true (note that since 7 is NOT greater than 8, then this is ALWAYS false)
5) if either (7 > 6 OR 3 > 4), then exprn == NOT true == false

Hope this helps. Pick up a book on formal logic (in the philosophy section of the library). That was my most useful undergraduate class for my programming career.

Edited 4 Years Ago by rubberman: n/a

The above questions are from a quiz on a programming site I am stuck on. Phorce I don't have to write them out in code.

rubberman thanks thats useful and helps me understand logical operators better. But it's the answers to the above questions or quiz I don't understand that I really need explaining or breaking down.

The answers are bellow:

1) (true && true) || false == true || false == true

2) (false && true) || true == false || true == true

3) (false && true) || false || true == false || false || true == false || true == true

4) (5 > 6 || 4 > 3) && (7 > 8) == (false || true) && false == true && false == false

5) !(7 > 6 || 3 > 4) == !(true || false) == !true == false

p.s to rubberman what does exprn mean? Thanks again.

(true && true) || false == true || false == true

I don't know how we could make that any simpler than it already is.

(true && true) || false

(true && true): This statement will be true overall if both sides of the && are true. Are they both true? Yes they are. So this statement is true.

Now replace (true && true) with true because we know they are the same thing because we just worked that out. So now the underlined statement has become:


true|| false

This statement will be true overall if either side of the || is true. Is the side on the left true? Yes is is. So this statement is true. We can replace the second underlined statement with

true

because we know they are the same thing because we just worked that out.

Repeat for the others.

I tried to be as clear as I could so that you could understand the flow. You need to study and understand truth tables to really get this stuff, which is what you learn in formal logic classes. Sorry, but my studies in this were so long ago (45 years) that I don't have any texts to refer you to, but there are myriads, which should show up in a Google or Wikipedia search.

Thanks Moschops and rubberman. Rubberman I will google formal logic and truth tables and see if I can find anything on them in the libary...should I look in the philosophy section or another section? Many thanks again.

true|| false

This statement will be true overall if either side of the || is true. Is the side on the left true? Yes is is. So this statement is true. We can replace the second underlined statement with

true

because we know they are the same thing because we just worked that out.

So in regard to :(true && true) || false == true || false == true

(true && true)|| false (the statement on the left is true so the statement (true && true) || false is TRUE so does it end there? What is the second false == true on the right for or/and what does it mean?

Many thanks again.

(true && true) || false == true || false == true

is logically the same as

((true && true) || false == true) || false == true

A==B is true if A is equal to B else false. || has higher precedence than == so on the right its (true||false)==true which is true since true||false is true equal to true

This article has been dead for over six months. Start a new discussion instead.