When will the print statement be executed in the code below? The program would exit early and not assign the value to the age property. func setAge(age: Int) { guard age >= 18 else {   print("You are \(age) years old")   return   } self.age = age }

Programming with Microsoft Visual Basic 2017
8th Edition
ISBN:9781337102124
Author:Diane Zak
Publisher:Diane Zak
Chapter10: Classes And Objects
Section: Chapter Questions
Problem 11RQ
icon
Related questions
Question

6. 

When will the print statement be executed in the code below? The program would exit early and not assign the value to the age property.

func setAge(age: Int) {
guard age >= 18 else {
  print("You are \(age) years old")
  return
  }
self.age = age
}

When will the print statement be executed in the code below? The program would exit early and not assign the value to the age property.

func setAge(age: Int) {
guard age >= 18 else {
  print("You are \(age) years old")
  return
  }
self.age = age
}
1. When the value of age is less than 18.
 
2. When the value of age is greater than or equal to 18.
 
3. After the guard block finishes executing.
 
4. It will never be called.
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Dictionary
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning