Simple Processing: Subtraction operator

The subtraction operator, -, is very similar to the addition operator. When used with numeric types of variables it performs the mathematical operation of subtraction, i.e. the value on the right hand side of the operator is subtracted from the value on the left hand side. You cannot use this operator with string types.

It is possible to use the subtraction operator in a normal manner, where the result of the subtraction is used with another operator or as a parameter to a command, or in the shortcut mode shown in the previous page. The same restrictions apply as with the addition operator: the result of the calculation must not be used and the leftmost item must be a variable (so that it can be decreased).

This example demonstrates some of the uses of the subtraction operator. You can get the source here.

OpenConsole()

; Part 1 - Simple example of using the subtraction operator
x2 = 50
x1 = 25
distance = x2 - x1
PrintN("Distance between two points: " + Str(distance))

; Part 2 - Multiple operators can be used in the same calculation
total = 100
half = 50
quarter = 25
tenth = 10
leftovers = total - half - quarter - tenth - 2
PrintN("Remaining quantity: " + Str(leftovers))

; Part 3 - Shortcut version of the subtraction operator
leftovers - 3
PrintN("After decreasing using shortcut method: " + Str(leftovers))

PrintN("Press return to exit")
Input()
CloseConsole()
End

Output of the subtraction example This image shows the output of the example program.