0
0
Swiftprogramming~20 mins

Logical operators in Swift - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Logical Operators Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of combined logical operators
What is the output of this Swift code snippet?
Swift
let a = true
let b = false
let c = true
print(a && b || c)
Atrue
Bfalse
Cnil
DCompilation error
Attempts:
2 left
💡 Hint
Remember that && has higher precedence than || in Swift.
Predict Output
intermediate
2:00remaining
Result of negation and OR operator
What does this Swift code print?
Swift
let x = false
let y = true
print(!x || y)
Anil
Btrue
Cfalse
DRuntime error
Attempts:
2 left
💡 Hint
Negation (!) flips the boolean value.
Predict Output
advanced
2:00remaining
Output of complex logical expression
What is the output of this Swift code?
Swift
let p = false
let q = true
let r = false
print((p || q) && !r)
ACompilation error
Bnil
Ctrue
Dfalse
Attempts:
2 left
💡 Hint
Evaluate inside parentheses first, then apply negation and AND.
Predict Output
advanced
2:00remaining
Value of variable after logical operations
What is the value of variable result after running this Swift code?
Swift
let a = true
let b = false
let c = true
let result = !(a && b) && (b || c)
print(result)
Atrue
Bnil
CCompilation error
Dfalse
Attempts:
2 left
💡 Hint
Break down the expression step by step.
Predict Output
expert
2:00remaining
Output of chained logical operators with precedence
What does this Swift code print?
Swift
let x = false
let y = true
let z = false
print(x || y && !z || false)
Anil
Bfalse
CCompilation error
Dtrue
Attempts:
2 left
💡 Hint
Remember that && has higher precedence than ||, and negation applies before &&.