You need to study more on logical reasoning, and then practice on algorithms...
I will approach 2 matters for you to understand better, which are:
1) Truth Table
2) Logical Operators
What is Truth-Table?
Truth table, truth table or veritative table is a type of mathematical table used in logic to determine whether a formula is valid or whether a sequent is correct.
What are Logical Operators?
Logical operator, as well as an arithmetic operator, is an operation class on predefined variables or elements. AND
, NAND
, OR
, XOR
and NOT
are the main logical operators, basis for the construction of digital systems and propositional logic, and also widely used in programming language. Operators AND
, NAND
, OR
and XOR
are binary operators, that is, they need two elements, while the NOT
is unary. In computation, these elements are usually binary variables, whose possible assigned values are 0
or 1
. However, the logic used for these variables also serves for sentences (sentences) of human language, where if this is truth corresponds to the value 1
, and if it is false corresponds to the value 0
.
Now, let’s practice, all right? I will approach giving simple examples and the main logical gates with their respective truth-table for you to better understand their logic.
Illustration of the main logical gates and their respective truth table:
Porta Lógica NOT
:
This door she is a door of denial, ie if you notice in her truth table, when the entrance A
receives 0
(false-off) it turns the output into 1
(true-connected) and when she receives 1
it turns the output into 0
. Algorithm example:
if(!isLarge){
} else {}
What I mean by this code is the following: If it is different from great enter this if
, else get in the else
.
Porta Lógica AND
:
This door checks the condition of the two entrances, to enter the given condition, the two entries must be true, so much that you can analyze in its truth table, she only has the output 1
(truth) when the two entries have the values 1
and 1
. Algorithm example:
if(isLarge && tamanho == 50.00){
} else{}
What I mean by this code is this: If it is great and the size is equal to 50 cm enter the if
, else get in the else
.
Porta Lógica OR
:
This door checks the condition of the two entrances, but it is different from the AND
, for to be true at least one of the entries must have the value 1
, you can notice in your table that it is only true when one of the entries has the value 1
or both have the value 1
. Algorithm example:
if(isLarge || tamanho == 50.00){
} else{}
What I mean by this code is this: If it is great and the if the size is equal to 50 cm enter the if
, else get in the else
. Regardless if it is not great and the size is equal to 50 cm if it is great and the size is different from 50 cm she entered the if
, if it’s not great and the size is not equal to 50 cm she entered the else
.
My answer became adequate and easy to understand for you?
– user148754
you are messing with short circuit operators, one of the parts that is evaluated, the other will be ignored and results in TRUE in the case of OR. And I didn’t quite understand the code proposal.
– Dr.G
You want ONLY to know which number is bigger or which is bigger?
– Sam