Operators and conditions summary
You’ve made it to the end of the third part of this series, so let’s summarize:
- Swift has operators for doing arithmetic and for comparison; they mostly work like you already know.
- There are compound variants of arithmetic operators that modify their variables in place:
-=, and so on.
- You can use
else if to run code based on the result of a condition.
- Swift has a ternary operator that combines a check with true and false code blocks. Although you might see it in other code, I wouldn’t recommend using it yourself.
- If you have multiple conditions using the same value, it’s often clearer to use
- You can make ranges using
... depending on whether the last number should be excluded or included.
Want to build macOS apps?
Hacking with macOS delivers 18 awesome projects that teach you macOS development in no time – take control of your desktop today!