Mixly Block Category - Logic

From Microduino Wiki
Revision as of 00:34, 22 February 2017 by Sonny (talk) (Boolean Values)
Jump to: navigation, search

Relational Operators

Takes two inputs -- left and right. Performs the requested relational operator (see below). If the statement is true (correct), then a boolean true is returned. If false (incorrect), then a boolean false is returned. Boolean values are useful in if statements to decide to do a set of blocks or not. And in loops to continue looping or not.

  • Left Input - The first value that will be used in the relational statement.
  • Relational Operator - The operator used -- equal, not equal, less than, left than or equal, greater than, greater than or equal.
  • Second Input - The second that will be used in the relational statement.

Equal

Compares the two inputs for equality. If equal, then true is returned, otherwise false is returned.


Example 1: [5 = 5], returns true.

Example 2: [5 = 6], returns false.

Not Equal

Compares the two inputs being different. If different (not equal), then true is returned, otherwise false is returned. This is the reverse of the Equal operator.


Example 1: [5 5], returns false.

Example 2: [5 6], returns true.

Less Than

Compares the Left Input is less than the Right Input. If correct, then true is returned, otherwise false is returned.


Example 1: [5 < 6], returns true.

Example 2: [5 < 5], returns false.

Example 3: [5 < 4], returns false.

Less Than Or Equal

Compares the Left Input is less than or equal to the Right Input. If correct, then true is returned, otherwise false is returned.


Example 1: [5 6], returns true.

Example 2: [5 5], returns true.

Example 3: [5 4], returns false.

Greater Than

Compares the Left Input is greater than the Right Input. If correct, then true is returned, otherwise false is returned.


Example 1: [5 > 6], returns true.

Example 2: [5 > 5], returns false.

Example 3: [5 > 4], returns true.

Greater Than Or Equal

Compares the Left Input is greater than or equal to the Right Input. If correct, then true is returned, otherwise false is returned.


Example 1: [5 6], returns false.

Example 2: [5 5], returns true.

Example 3: [5 4], returns true.


Read more here: https://www.arduino.cc/en/Reference/If

Boolean Operations

Takes two inputs -- left and right. Performs the requested boolean operator (see below). Similiar to relational operators, but works with boolean values (true or false). If the statement is true (correct), then a boolean true is returned. If false (incorrect), then a boolean false is returned. Boolean values are useful in if statements to decide to do a set of blocks or not. And in loops to continue looping or not.

and

Performs an and boolean operator on the two inputs and returns a boolean (true or false) value. Below is the truth for the and boolean operator.

  • L is left input / input 1.
  • R is right input / input 2.
  • L and R is the result of the and operator performed on the two inputs.
L R L and R
true true true
true false false
false true false
false false false


Read more here: https://www.arduino.cc/en/reference/boolean

or

Performs an or boolean operator on the two inputs and returns a boolean (true or false) value. Below is the truth for the or boolean operator.

  • L is left input / input 1.
  • R is right input / input 2.
  • L and R is the result of the or operator performed on the two inputs.
L R L or R
true true true
true false true
false true true
false false false


Read more here: https://www.arduino.cc/en/reference/boolean

Not (Negation)

Returns the invert of the input.

  • If input is true, return false.
  • If input is false, return true.


Read more here: https://www.arduino.cc/en/reference/boolean

Boolean Values

Boolean values are a data type that can only be true or false. They are used in condtiion statements such as if and loops. These checks a boolean value or a statement that evaluates to a boolean value and determines if the contents are executed or looped (if true) or skips (if false).


Read more here: https://www.arduino.cc/en/Reference/BooleanVariables

null Value

null is a value of no value. It is usually used for uninitialized variables or pointers. It can be assigned to most objects or variables.

... if true ... if false ...

This function checks the input 1 for true or false. If input 1 is true, then input 2 is returned. Otherwise, input 2 is returned.

  • Input 1 - The condition check value or variable. Determines whether Input 2 or Input 3 is returned.
  • Input 2 - This is returned if Input 1 is true.
  • Input 3 - This is returned if Input 1 is false.


Example 1: [true if true Input 2 if else Input 3] returns Input 2

Example 2: [false if true Input 2 if else Input 3] returns Input 3