SlideShare a Scribd company logo
Unit 1—Lesson 3:

Operators
Assign a value
Use the = operator to assign a value

var favoritePerson = "Luke"
Use the = operator to modify or reassign a value

var shoeSize = 8
shoeSize = 9
Basic arithmetic
You can use the +, -, *, and / operators to perform basic math functions

var opponentScore = 3 * 8
var myScore = 100 / 4
You can also use the value of other variables

var totalScore = opponentScore + myScore
Or you can use the current variable you’re updating

myScore = myScore + 3
Basic arithmetic
Use Double values for decimal point precision

let totalDistance = 3.9
var distanceTravelled = 1.2
var remainingDistance = totalDistance - distanceTravelled
print(remainingDistance)
2.7
Basic arithmetic
let x = 51
let y = 4
let z = x / y
print(z)
12
Using Double values
Basic arithmetic
let x: Double = 51
let y: Double = 4
let z = x / y
print(z)
12.75
Compound assignment
var myScore = 10
myScore = myScore + 3
myScore += 3
myScore -= 5
myScore *= 2
myScore /= 2
Order of operations
1. ( )

2. * /

3. + -

var x = 2
var y = 3
var z = 5

print(x + y * z)
print((x + y) * z)
17
25
Numeric type conversion
let x = 3
let y = 0.1415927
let pi = x + y Binary operator ‘+’ cannot be applied to operands of type ‘Int’ and ‘Double’!
Numeric type conversion
let x = 3
let y = 0.1415927
let pi = Double(x) + y
Lab: Operators
Unit 1—Lesson 3
Open and complete the exercises in Lab-Operators.playground
© 2017 Apple Inc. 

This work is licensed by Apple Inc. under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International license.

More Related Content

PPS
Order of Operations
PPTX
Lecture two
PPTX
Error analysis
PPTX
PDF
Bisection method
PPTX
Bisection method
PPTX
Approximation and error
Order of Operations
Lecture two
Error analysis
Bisection method
Bisection method
Approximation and error

What's hot (20)

PDF
Associativity of operators
PPTX
Linear regression by Kodebay
PPT
Numerical Method
PPTX
Calculation of mode
PPTX
Bisection Method
PDF
A NEW STUDY OF TRAPEZOIDAL, SIMPSON’S1/3 AND SIMPSON’S 3/8 RULES OF NUMERICAL...
PPT
Numerical integration
PPTX
V24 cartesion product-c
PPTX
weddle's rule
PDF
Arrays and its properties IN SWIFT
DOCX
Bisection method
 
PPTX
Newton cotes integration method
PDF
Chapter two
PPTX
Presentation on Numerical Method (Trapezoidal Method)
PDF
Numerical Method Analysis: Algebraic and Transcendental Equations (Linear)
PPTX
Greatest integer
PPTX
Multiple sagement trapezoidal rule
PPT
Calc 4.6
PDF
Open newton cotes quadrature with midpoint derivative for integration of al...
PDF
Integration
Associativity of operators
Linear regression by Kodebay
Numerical Method
Calculation of mode
Bisection Method
A NEW STUDY OF TRAPEZOIDAL, SIMPSON’S1/3 AND SIMPSON’S 3/8 RULES OF NUMERICAL...
Numerical integration
V24 cartesion product-c
weddle's rule
Arrays and its properties IN SWIFT
Bisection method
 
Newton cotes integration method
Chapter two
Presentation on Numerical Method (Trapezoidal Method)
Numerical Method Analysis: Algebraic and Transcendental Equations (Linear)
Greatest integer
Multiple sagement trapezoidal rule
Calc 4.6
Open newton cotes quadrature with midpoint derivative for integration of al...
Integration
Ad

Similar to Operators (20)

PPT
FP 201 Unit 2 - Part 3
PDF
Operators in python
PPT
operator ppt.ppt
PPT
Reportgroup4 111016004939-phpapp01
PDF
C Programming Language (Operators and Expression)
ODT
Php Tutorial
PDF
ICP - Lecture 5
PPT
Fundamentals of Programming Chapter 5
PPTX
Operator
PPTX
Operator in c programming
PPT
Project in TLE
PPTX
Different Types of Operators in Python.pptx
PPTX
Operators Concept in Python-N.Kavitha.pptx
PPT
Report Group 4 Constants and Variables
PPT
Report Group 4 Constants and Variables(TLE)
PPTX
Lesson 1 - Intro to Arithmetic Operators.pptx
PPTX
datatypes-and-operators in wed development.pptx
PPT
operator
PPTX
Opreator In "C"
PPTX
Cse lecture-4.1-c operators and expression
FP 201 Unit 2 - Part 3
Operators in python
operator ppt.ppt
Reportgroup4 111016004939-phpapp01
C Programming Language (Operators and Expression)
Php Tutorial
ICP - Lecture 5
Fundamentals of Programming Chapter 5
Operator
Operator in c programming
Project in TLE
Different Types of Operators in Python.pptx
Operators Concept in Python-N.Kavitha.pptx
Report Group 4 Constants and Variables
Report Group 4 Constants and Variables(TLE)
Lesson 1 - Intro to Arithmetic Operators.pptx
datatypes-and-operators in wed development.pptx
operator
Opreator In "C"
Cse lecture-4.1-c operators and expression
Ad

More from SV.CO (20)

PDF
Handout level-1-module-1
PDF
Persistence And Documents
PDF
Building complex input screens
PDF
Working with the Web: 
Decoding JSON
PDF
Saving Data
PDF
Alerts notification
PDF
UI Dynamics
PDF
Practical animation
PDF
Segues and navigation controllers
PDF
Camera And Email
PDF
Scroll views
PDF
Intermediate table views
PDF
Table views
PDF
Closures
PDF
Protocols
PDF
App anatomy and life cycle
PDF
Extensions
PDF
Gestures
PDF
View controller life cycle
PDF
Controls in action
Handout level-1-module-1
Persistence And Documents
Building complex input screens
Working with the Web: 
Decoding JSON
Saving Data
Alerts notification
UI Dynamics
Practical animation
Segues and navigation controllers
Camera And Email
Scroll views
Intermediate table views
Table views
Closures
Protocols
App anatomy and life cycle
Extensions
Gestures
View controller life cycle
Controls in action

Recently uploaded (20)

PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
master seminar digital applications in india
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Pharma ospi slides which help in ospi learning
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Cell Types and Its function , kingdom of life
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PDF
Microbial disease of the cardiovascular and lymphatic systems
Final Presentation General Medicine 03-08-2024.pptx
master seminar digital applications in india
Complications of Minimal Access Surgery at WLH
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Week 4 Term 3 Study Techniques revisited.pptx
human mycosis Human fungal infections are called human mycosis..pptx
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
STATICS OF THE RIGID BODIES Hibbelers.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
O7-L3 Supply Chain Operations - ICLT Program
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
Pharma ospi slides which help in ospi learning
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
VCE English Exam - Section C Student Revision Booklet
Cell Types and Its function , kingdom of life
FourierSeries-QuestionsWithAnswers(Part-A).pdf
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
Microbial disease of the cardiovascular and lymphatic systems

Operators

  • 2. Assign a value Use the = operator to assign a value var favoritePerson = "Luke" Use the = operator to modify or reassign a value var shoeSize = 8 shoeSize = 9
  • 3. Basic arithmetic You can use the +, -, *, and / operators to perform basic math functions var opponentScore = 3 * 8 var myScore = 100 / 4 You can also use the value of other variables var totalScore = opponentScore + myScore Or you can use the current variable you’re updating myScore = myScore + 3
  • 4. Basic arithmetic Use Double values for decimal point precision let totalDistance = 3.9 var distanceTravelled = 1.2 var remainingDistance = totalDistance - distanceTravelled print(remainingDistance) 2.7
  • 5. Basic arithmetic let x = 51 let y = 4 let z = x / y print(z) 12
  • 6. Using Double values Basic arithmetic let x: Double = 51 let y: Double = 4 let z = x / y print(z) 12.75
  • 7. Compound assignment var myScore = 10 myScore = myScore + 3 myScore += 3 myScore -= 5 myScore *= 2 myScore /= 2
  • 8. Order of operations 1. ( ) 2. * / 3. + - var x = 2 var y = 3 var z = 5
 print(x + y * z) print((x + y) * z) 17 25
  • 9. Numeric type conversion let x = 3 let y = 0.1415927 let pi = x + y Binary operator ‘+’ cannot be applied to operands of type ‘Int’ and ‘Double’!
  • 10. Numeric type conversion let x = 3 let y = 0.1415927 let pi = Double(x) + y
  • 11. Lab: Operators Unit 1—Lesson 3 Open and complete the exercises in Lab-Operators.playground
  • 12. © 2017 Apple Inc. This work is licensed by Apple Inc. under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International license.