Understanding AND Logic
+22
kylenicole
Alliah Faith
Emie Ligutan
Lhexmhar
Ferre
Bermon O. Ferreras Jr
rapzie badoodles
RicManipon
nyela
Admin
Myra Monique Acuna
Asdfghjkl
Pox
Lawrence
althea faye
James Navarro
Sean Monacillo
Luwiezz
airojames
JULIAN
justjoking10
ilovebts
26 posters
Understanding AND Logic
Wed Jul 25, 2018 9:05 am
Using the AND Operator
Most programming languages allow you to ask two or more questions in a single comparison by using a conditional AND operator , or more simply, an AND operator that joins decisions in a single expression.
When you use one or more AND operators to combine two or more Boolean expressions, each Boolean expression must be true for the entire expression to be evaluated as true. For example, if you ask, “Are you a native-born U.S. citizen and are you at least 35 years old?”, the answer to both parts of the question must be yes before the response can be a single, summarizing yes. If either part of the expression is false, then the entire expression is false.
One tool that can help you understand the AND operator is a truth table. Truth tables are diagrams used in mathematics and logic to help describe the truth of an entire expression based on the truth of its parts. Quick Reference 3-1 contains a truth table that lists all the possibilities with an AND operator. As the table shows, for any two expressions x and y , the expression x AND y is true only if both x and y are individually true. If either x or y alone is false, or if both are false, then the expression x AND y is false.
. Quick Reference 3-1 AND Logic Truth Table
For example, if you want to bill an extra amount to cell phone customers who make more than 100 calls that total more than 500 minutes in a billing period, you can use nested decisions, as shown in the previous section, or you can include both decisions in a
single expression by writing the following question:
callsMade > CALLS AND callMinutes > MINUTES
If the programming language you use allows an AND operator, you must realize that the question you place first (to the left of the AND operator) is the one that will be asked first, and cases that are eliminated based on the first question will not proceed to the second question. In other words, each part of an expression that uses an AND operator is evaluated only as far as necessary to determine whether the entire expression is true or false. This feature is called short-circuit
evaluation . The computer can ask only one question at a time; even when your pseudocode looks like the first example in Figure 3-1, the computer will execute the logic shown in the second example. Even when you use an AND operator, the computer makes decisions one at a time, and makes them in the order you ask them. As you can see in the truth table, if the first question in an AND expression evaluates to false, then the entire expression is false. In that
case, there is no point in evaluating the second Boolean expression. In other words, evaluating an AND expression is interrupted as soon as part of it is determined to be false.
You are never required to use the AND operator because using nested if statements can always achieve the same result. However, using the AND operator often makes your code more concise, less error-prone, and easier to understand.
Figure 3-1 Using an AND operator and the logic behind it
Logic Example
Figure 3-2 A coffee vending machine
Let's say for example x is the 5(five) peso coin, y is the flavor button, and the result is the coffee.
Will it give you a fresh hot coffee or not? Check this Truth Table.
Most programming languages allow you to ask two or more questions in a single comparison by using a conditional AND operator , or more simply, an AND operator that joins decisions in a single expression.
When you use one or more AND operators to combine two or more Boolean expressions, each Boolean expression must be true for the entire expression to be evaluated as true. For example, if you ask, “Are you a native-born U.S. citizen and are you at least 35 years old?”, the answer to both parts of the question must be yes before the response can be a single, summarizing yes. If either part of the expression is false, then the entire expression is false.
One tool that can help you understand the AND operator is a truth table. Truth tables are diagrams used in mathematics and logic to help describe the truth of an entire expression based on the truth of its parts. Quick Reference 3-1 contains a truth table that lists all the possibilities with an AND operator. As the table shows, for any two expressions x and y , the expression x AND y is true only if both x and y are individually true. If either x or y alone is false, or if both are false, then the expression x AND y is false.
. Quick Reference 3-1 AND Logic Truth Table
For example, if you want to bill an extra amount to cell phone customers who make more than 100 calls that total more than 500 minutes in a billing period, you can use nested decisions, as shown in the previous section, or you can include both decisions in a
single expression by writing the following question:
callsMade > CALLS AND callMinutes > MINUTES
If the programming language you use allows an AND operator, you must realize that the question you place first (to the left of the AND operator) is the one that will be asked first, and cases that are eliminated based on the first question will not proceed to the second question. In other words, each part of an expression that uses an AND operator is evaluated only as far as necessary to determine whether the entire expression is true or false. This feature is called short-circuit
evaluation . The computer can ask only one question at a time; even when your pseudocode looks like the first example in Figure 3-1, the computer will execute the logic shown in the second example. Even when you use an AND operator, the computer makes decisions one at a time, and makes them in the order you ask them. As you can see in the truth table, if the first question in an AND expression evaluates to false, then the entire expression is false. In that
case, there is no point in evaluating the second Boolean expression. In other words, evaluating an AND expression is interrupted as soon as part of it is determined to be false.
You are never required to use the AND operator because using nested if statements can always achieve the same result. However, using the AND operator often makes your code more concise, less error-prone, and easier to understand.
Figure 3-1 Using an AND operator and the logic behind it
Logic Example
Figure 3-2 A coffee vending machine
Let's say for example x is the 5(five) peso coin, y is the flavor button, and the result is the coffee.
Will it give you a fresh hot coffee or not? Check this Truth Table.
Did you UNDERSTAND AND LOGIC?
If yes, would you please give different example/application of it?
else comment down below your reactions/questions.
If yes, would you please give different example/application of it?
else comment down below your reactions/questions.
- ilovebtsGuru
- Posts : 11
Join date : 2018-08-01
Re: Understanding AND Logic
Wed Aug 01, 2018 4:13 pm
Wow! This is so amazing. You explained it very well and the examples are really easy to interpret! But can I ask you if I am allowed to use two operators at the same time? Thank you! I hope someone we'll get to answer my question.
Re: Understanding AND Logic
Wed Aug 01, 2018 4:22 pm
ilovebts wrote:Wow! This is so amazing. You explained it very well and the examples are really easy to interpret! But can I ask you if I am allowed to use two operators at the same time? Thank you! I hope someone we'll get to answer my question.
Thank you Rash! Yes you can use two operators at the same time even three or more.
- ilovebtsGuru
- Posts : 11
Join date : 2018-08-01
Re: Understanding AND Logic
Wed Aug 01, 2018 4:25 pm
Admin wrote:ilovebts wrote:Wow! This is so amazing. You explained it very well and the examples are really easy to interpret! But can I ask you if I am allowed to use two operators at the same time? Thank you! I hope someone we'll get to answer my question.
Thank you Rash! Yes you can use two operators at the same time even three or more.
Thank you Jude! But can you give me an example na gumagamit ng two or more operators?
Re: Understanding AND Logic
Wed Aug 01, 2018 4:52 pm
ilovebts wrote:Admin wrote:ilovebts wrote:Wow! This is so amazing. You explained it very well and the examples are really easy to interpret! But can I ask you if I am allowed to use two operators at the same time? Thank you! I hope someone we'll get to answer my question.
Thank you Rash! Yes you can use two operators at the same time even three or more.
Thank you Jude! But can you give me an example na gumagamit ng two or more operators?
For example, assume that you need to achieve a score of at least 75 on each of three tests to pass a course.You can declare a constant MIN_SCORE equal to 75 and test the multiple conditions with a statement like the following:
if score1 >= MIN_SCORE AND score2 >= MIN_SCORE AND score3 >= MIN_SCORE then
classGrade = "Pass"
else
classGrade = "Fail"
endif
- justjoking10Guru
- Posts : 19
Join date : 2018-08-01
Re: Understanding AND Logic
Wed Aug 01, 2018 6:13 pm
Sir. Is this right for the coffee vending machine example?
Just like in your example 1 represents TRUE and 0 represents FALSE.
Let X be the 5 peso coin and Y be the pressed button.
if X = 1 AND Y = 1 then
COFFEE
else
NO COFFEE
end if
If there is a better way to present it in pseudocode please reply.
Just like in your example 1 represents TRUE and 0 represents FALSE.
Let X be the 5 peso coin and Y be the pressed button.
if X = 1 AND Y = 1 then
COFFEE
else
NO COFFEE
end if
If there is a better way to present it in pseudocode please reply.
Re: Understanding AND Logic
Wed Aug 01, 2018 6:25 pm
don't expect that there is only 1 coin nor flavor, so you can use this:justjoking10 wrote:Sir. Is this right for the coffee vending machine example?
Just like in your example 1 represents TRUE and 0 represents FALSE.
Let X be the 5 peso coin and Y be the pressed button.
if X = 1 AND Y = 1 then
COFFEE
else
NO COFFEE
end if
If there is a better way to present it in pseudocode please reply.
if coin <> 0 AND flavor <>0
Give Coffee
else
No Coffee
- justjoking10Guru
- Posts : 19
Join date : 2018-08-01
Re: Understanding AND Logic
Wed Aug 01, 2018 6:32 pm
Ok sir. I would expand my thinking to a more flexible and realistic manner next time. Thank you for a clear answer.
- JULIAN
- Posts : 1
Join date : 2018-08-01
Re: Understanding AND Logic
Wed Aug 01, 2018 6:33 pm
Can you site anothee examples sir so That we can clearly understand the logic sir?? Please???.
- airojamesGuru
- Posts : 11
Join date : 2018-08-01
Re: Understanding AND Logic
Wed Aug 01, 2018 6:50 pm
yes! may paexample si sir!
Re: Understanding AND Logic
Wed Aug 01, 2018 6:57 pm
woah! that's good as a programmer. To practice that, would you give another example of application of AND in our daily life?justjoking10 wrote:Ok sir. I would expand my thinking to a more flexible and realistic manner next time. Thank you for a clear answer.
Re: Understanding AND Logic
Wed Aug 01, 2018 6:58 pm
para higit na maunawaan ng mambabasaairojames wrote:yes! may paexample si sir!
- airojamesGuru
- Posts : 11
Join date : 2018-08-01
Re: Understanding AND Logic
Wed Aug 01, 2018 7:02 pm
sir pwede po ba gamitin yung tatlong logic sa isang program na magkakasama?(and,not,or)
Re: Understanding AND Logic
Wed Aug 01, 2018 7:05 pm
What part is not clear to you?JULIAN wrote:Can you site anothee examples sir so That we can clearly understand the logic sir?? Please???.
- justjoking10Guru
- Posts : 19
Join date : 2018-08-01
Re: Understanding AND Logic
Wed Aug 01, 2018 9:27 pm
Admin wrote:woah! that's good as a programmer. To practice that, would you give another example of application of AND in our daily life?justjoking10 wrote:Ok sir. I would expand my thinking to a more flexible and realistic manner next time. Thank you for a clear answer.
Try po sir. S pagkain may Go Grow and Glow foods. Sabi nila para maging healthy dpt kumain non.
if Go <> 0 AND Grow <> 0 AND Glow <> 0 then
PERSON IS HEALTHY
else
PERSON IS UNHEALTHY
endif
Re: Understanding AND Logic
Thu Aug 02, 2018 7:38 am
Pwede para maging mas epektibo ang iyong program. Tandaan lamang na dapat tama ang paggamit sa mga logic na ito.airojames wrote:sir pwede po ba gamitin yung tatlong logic sa isang program na magkakasama?(and,not,or)
Re: Understanding AND Logic
Thu Aug 02, 2018 7:39 am
That's right. Talagang nauunawaan mo na ang AND Logic.justjoking10 wrote:Admin wrote:woah! that's good as a programmer. To practice that, would you give another example of application of AND in our daily life?justjoking10 wrote:Ok sir. I would expand my thinking to a more flexible and realistic manner next time. Thank you for a clear answer.
Try po sir. S pagkain may Go Grow and Glow foods. Sabi nila para maging healthy dpt kumain non.
if Go <> 0 AND Grow <> 0 AND Glow <> 0 then
PERSON IS HEALTHY
else
PERSON IS UNHEALTHY
endif
- ilovebtsGuru
- Posts : 11
Join date : 2018-08-01
Re: Understanding AND Logic
Thu Aug 02, 2018 8:00 am
airojames wrote:sir pwede po ba gamitin yung tatlong logic sa isang program na magkakasama?(and,not,or)
Of course! Kaso baka di mo sya magamit ng maayos and maglead sya sa magulong program.
- ilovebtsGuru
- Posts : 11
Join date : 2018-08-01
Re: Understanding AND Logic
Thu Aug 02, 2018 8:05 am
Naks naman! At your service si Admin!Admin wrote:para higit na maunawaan ng mambabasaairojames wrote:yes! may paexample si sir!
- ilovebtsGuru
- Posts : 11
Join date : 2018-08-01
Re: Understanding AND Logic
Thu Aug 02, 2018 8:05 am
Payaman!airojames wrote:yes! may paexample si sir!
- ilovebtsGuru
- Posts : 11
Join date : 2018-08-01
Re: Understanding AND Logic
Thu Aug 02, 2018 8:11 am
Admin wrote:ilovebts wrote:Admin wrote:ilovebts wrote:Wow! This is so amazing. You explained it very well and the examples are really easy to interpret! But can I ask you if I am allowed to use two operators at the same time? Thank you! I hope someone we'll get to answer my question.
Thank you Rash! Yes you can use two operators at the same time even three or more.
Thank you Jude! But can you give me an example na gumagamit ng two or more operators?
For example, assume that you need to achieve a score of at least 75 on each of three tests to pass a course.You can declare a constant MIN_SCORE equal to 75 and test the multiple conditions with a statement like the following:
if score1 >= MIN_SCORE AND score2 >= MIN_SCORE AND score3 >= MIN_SCORE then
classGrade = "Pass"
else
classGrade = "Fail"
endif
Thank you so so much! This helped me a lot.
Re: Understanding AND Logic
Thu Aug 02, 2018 5:51 pm
Paawerr!ilovebts wrote:Payaman!airojames wrote:yes! may paexample si sir!
Re: Understanding AND Logic
Thu Aug 02, 2018 6:00 pm
Yes! I love to help others with this forum.ilovebts wrote:Naks naman! At your service si Admin!Admin wrote:para higit na maunawaan ng mambabasaairojames wrote:yes! may paexample si sir!
- LuwiezzNewbie
- Posts : 3
Join date : 2018-08-02
Re: Understanding AND Logic
Thu Aug 02, 2018 6:54 pm
Sir is it possible na magamit sa iisang program ang NOT, OR, AND? Or NOT, OR or NOT, AND?
- RicManiponGuru
- Posts : 10
Join date : 2018-08-02
Re: Understanding AND Logic
Thu Aug 02, 2018 7:13 pm
Sir any programming language possible yung NOT logic?
Sent from Topic'it App
Sent from Topic'it App
Permissions in this forum:
You cannot reply to topics in this forum
|
|