Operations with our Integers
In our Playground, we know that numAge
is an Int, but with Ints, we also can write arithmetic expressions using numbers, variables/constants, operators, and parentheses. Let's start with addition, subtraction, multiplication, and division. Add the following into Xcode:
// (+) operator let numSum = 23 + 20 // (-) operator let numResult = 32 - numSum // (*) operator let numTotal = numResult * 5 // (/) operator let numDivide = numTotal / 10
So, numSum
added two integers (+
operator) together, totaling 43
in our preceding example. Then, we subtracted (-
operator) numSum
from 32
to create numResult
(−11
in our example). After ...
Get iOS 10 Programming for Beginners now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.