Unit 2: Naming & Identifiers Flashcards
Assignment
used to give a name a value when you first declare a name or when you update a variable’s value
Constant
an identifier that’s immutable
Declaration
introduces a new name or construct into your program
used to introduce functions, methods, variables, and constants, as well as to define new named types
Identifier
refers to a value, function, type or any other abstraction
a formal word for a name in code
Keyword
a term that has a special meaning in Swift and can’t be used for any other purposes
e.g.,
func (keyword) can’t be used in this example:
var func
Pet Problem
Using Xcode, I can create a playground that details the number of animals available for the show.
E.g.,
//Number Of Dogs 5
//Number of Cats 4
//Number of Turtles 3
計算モード
// Total Number of Animals 5+4+3 12
//Total Number of Mammals 5 + 4 9
Defining a Constant
To define a constant, please follow the example below:
Let numberOfDogs = 6
Let numberOfCats = 5
Let numberOfTurtles = 2
Let numberOfHamsters = 1
*After defining a constant and assigning a value to it, you can use the constant wherever you would have used the value, including in mathematical calculations that define the value of a new constant: