Foundations
Variables and Constants
Use let for values that should not change and var for values that can be
updated later.
Compute with stored values
variables.swift
let unitPrice =
let quantity = 3
var total = unitPrice * quantity
total = total + 5
print("unit=\(unitPrice)")
print("total=\(total)")
let unitPrice =
let quantity = 3
var total = unitPrice * quantity
total = total + 5
print("unit=\(unitPrice)")
print("total=\(total)")
let unitPrice =
let quantity = 3
var total = unitPrice * quantity
total = total + 5
print("unit=\(unitPrice)")
print("total=\(total)")
let and var
`let` creates a constant. `var` creates a variable that can be assigned again.