________________________________________________________________________________________________________________ MOBILE MAKERS ACADEMY 223 W Erie, Suite 4NW, Chicago, IL 60654 www.mobilemakers.co
Learning Outcomes By the end of this topic, students should be able to: 1. Use appropriate punctuation to reach desired operation in programming. 2. Execute both arithmetic and comparison operators.
________________________________________________________________________________________________________________ MOBILE MAKERS ACADEMY 223 W Erie, Suite 4NW, Chicago, IL 60654 www.mobilemakers.co
Operators Operators are basic numeric functions that you can use in programming. Many of these should look familiar from Math, with a few differences. It’s important to note that the function of the operator is dependant on the type of punctuation. So, for example, you cannot use an x for multiplication, it must always be an asterisk (*). Note: we use the term foo as a placeholder for any variable or constant.
Arithmetic and Common Operators Operator
Definition
What it does
Example
Answer
foo1 = foo2
basic assignment
Assigns foo2 as foo1
logInAttempts = 15
n/a
foo1 + foo2
addition
Adds the two values
15 + 1
16
foo1 - foo2
subtraction
Subtracts foo2 from foo1
3 1
2
foo1 * foo2
multiplication
Multiples foo1 and foo2
15 * 1
15
foo1 / foo2
division
Divides foo1 and foo2
3 / 1
3
foo1 % foo2
remainder
The remainder of the division*
3 % 1
1
++foo1
increment
Increases foo1 by 1
++3
4
--foo1
decrement
Decreases foo1 by 1
3
2
* This operator lists the leftovers from foo1 being divided by foo2.
________________________________________________________________________________________________________________ MOBILE MAKERS ACADEMY 223 W Erie, Suite 4NW, Chicago, IL 60654 www.mobilemakers.co
Comparison Operators The following operators are used to compare two variables. This means that it will return a result of either true (either the comparison is correct) or false (the comparison is not correct). For example, the comparison 5 foo2