Exploring operators
You can perform arithmetic, comparison, and logical operations in Swift. Arithmetic operators are for common mathematical operations. Comparison and logical operators check an expression's value and return true
or false
.
Important Information
For more information on operators, visit https://docs.swift.org/swift-book/LanguageGuide/BasicOperators.html.
Let's look at each operator type in more detail. We'll start with arithmetic operators (addition, subtraction, multiplication, and division) in the next section.
Using arithmetic operators
You can perform mathematical operations on integer and floating-point numbers by using the standard arithmetic operators shown in the following table:
Let's see how these operators are used. Follow these steps:
- Add the following code to add arithmetic operations to your playground and click the Play/Stop button to run it:
let...