Bird
0
0

What will this Swift code print?

medium📝 Predict Output Q5 of 15
Swift - Loops
What will this Swift code print?
let names = ["Sam", "Lee", "Max"]
for name in names {
    print(name.uppercased())
}
Asam lee max
BSAM LEE MAX
CSam Lee Max
DError: uppercased() not found
Step-by-Step Solution
Solution:
  1. Step 1: Understand the loop and method

    The loop prints each name converted to uppercase using uppercased().
  2. Step 2: Predict output

    Each name will print in all capital letters on its own line.
  3. Final Answer:

    SAM LEE MAX -> Option B
  4. Quick Check:

    uppercased() converts strings to uppercase [OK]
Quick Trick: Use uppercased() to print uppercase strings [OK]
Common Mistakes:
  • Printing original names without uppercased()
  • Using lowercase method instead
  • Syntax errors in print statement

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes