LSP- Short-cut Operators and Relational Operators Lesson

Short-cut Operators and Relational Operators

Before you begin using loops and repetition in your programs, you need to understand relational and short-cut operators.

In the previous module, we reassigned variables like this:

int r = 10;

r = r + 5;                          

This reassigned the variable r to equal what r currently is + 5. This type of variable is called an accumulator. An accumulator is a variable that adds a value to itself.  

Since r is currently 10, r now equals 10+5. The variable r has been reassigned and now stores the value 15.          

This is important because we can use it to continually update and change the variables to change the x and y location, color, size, etc.

Short 

There are short-cut operators that will perform that operation

A short-cut operator is used in loops to increment and decrement variables. The ++ operator will increase a variable by 1 and the -- operator will decrease a variable by 1.

The short-cut operator is important in repetition because it is used for loops and while loops to increment the loop index variable. We will practice using this when we create our own loops in the next lesson.

Relational Operators

There are six relational operators: They are used to make comparisons. The result is always a true or false answer. Therefore the result will always be a boolean value.

There are six relational operators: They are used to make comparisons.

Boolean Expressions

The relational operators are used to form boolean expressions. A boolean expression results in a true or false answer.

These are examples of boolean expressions used in Processing.  Each of these will result in a true or false answer

x < 240

y   > 200

x < width

y < height

x <= 20  

Boolean Expressions Video

Watch the Boolean Expressions video below.

Creating While Statements Assignment

[CC BY 4.0] UNLESS OTHERWISE NOTED | IMAGES: LICENSED AND USED ACCORDING TO TERMS OF SUBSCRIPTION