Swift By Example - Values
Swift has a lot of the same kinds of value operators and expressions that you might be familiar with in other languages. Without getting into a bunch of theory, let’s just look at some code and figure out how values work in Swift.
print("hello " + "world") print("1+1 =", 1+1) print("7.0/3.0 =", 7.0/3.0) print(true && false) print(true || false) print(!true)
You’ll notice, the
1 + 1, but it can also combine two strings together such as
Floating point arithmetic (that is to say, the
7.0 / 3.0 expression), operates like normal. The boolean expressions (
true && false for example) are the same as what you would see in other languages.
Let’s see what values it produces! Save this as
To compile this and run in real-time, we can open up our handy Terminal, and type the following command:
$ swift values.swift hello world 1+1 = 2 7.0/3.0 = 2.3333333333333335 false true false