Lessons
|
Operator Blocks
Scratch has 3 operators that allow you to compare the relationship between two values or variables. It will compare the two and decide whether it is true or false. If the comparison is true, the program will go down to the next line of code and do what is there. If the comparison is false the code will not execute.
The three relational operators are:
Greater ThanThe block checks if the first value is greater than the other value. If it is less, the block returns true; if not, it returns false. This block works with letters too, not just numbers. In Scratch, letters at the top of the alphabet (e.g. a, b, c) are worth less than letters at the end (e.g. x, y, z).
Less thanThe block checks if the first value is less than the second value. If it is less, the block returns true; if not, it returns false. This block works with letters too, as well as numbers. In Scratch, letters at the top of the alphabet (e.g. a, b, c) are worth less than letters at the end (e.g. x, y, z).
Equals toThe block checks if the first value is equal to the other value. If the values are equal, the block returns true; if not, false.
Logic operatorsUsing logical operators, you can combine two or more relational operators to produce a single true/false result. Using these blocks allow you to further refine your comparison of values. There are 3 logic operators:
AndThe and operator takes two expressions as parameters. If both expressions are true, the and operator returns true; otherwise, it returns false.
OrThe or operator also takes two expressions as parameters. If either expression is true, the or operator returns true. It returns false only when the two expressions are both false.
NotThe not operator takes only one expression as input. The result of the operator is true if the expression is false and false if the expression is true.
|