Operators

Report 3 Downloads 347 Views
PAGE 1

iOS App Development

Operators

   ________________________________________________________________________________________________________________  MOBILE MAKERS ACADEMY 223 W Erie, Suite 4NW, Chicago, IL 60654 www.mobilemakers.co

© 2015 Mobile Makers Academy, LLC 

PAGE 2

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.

Vocabulary Operators Operator Precedence Foo = + * / % ++ --

   ________________________________________________________________________________________________________________  MOBILE MAKERS ACADEMY 223 W Erie, Suite 4NW, Chicago, IL 60654 www.mobilemakers.co

© 2015 Mobile Makers Academy, LLC 

PAGE 3

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

© 2015 Mobile Makers Academy, LLC 

PAGE 4

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

greater than

foo1 is greater than foo2

5 > 3 

true

foo1 >= foo2

greater than or equal to

foo1is greater than or equal to foo2

5 >= 3 

true

foo1 < foo2

less than

foo1 is less than foo2

3 , =,