Bird
0
0

Which of the following is the correct way to negate a Boolean variable isOpen in Swift?

easy📝 Syntax Q3 of 15
Swift - Operators and Expressions
Which of the following is the correct way to negate a Boolean variable isOpen in Swift?
AisOpen = &&isOpen
BisOpen = ||isOpen
CisOpen = !isOpen
DisOpen = ==isOpen
Step-by-Step Solution
Solution:
  1. Step 1: Identify the negation operator

    The NOT operator (!) negates a Boolean value in Swift.
  2. Step 2: Check syntax correctness

    Only isOpen = !isOpen uses ! correctly to negate the variable.
  3. Final Answer:

    isOpen = !isOpen -> Option C
  4. Quick Check:

    Negate Boolean with ! operator [OK]
Quick Trick: Use ! before variable to negate Boolean [OK]
Common Mistakes:
  • Using && or || to negate
  • Using == for negation
  • Missing ! operator

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes