Bird
0
0

What will be the output of this Swift program?

medium📝 Predict Output Q5 of 15
Swift - Basics and Runtime
What will be the output of this Swift program?
@main enum Runner {
    static func main() {
        for i in 1...3 {
            print(i)
        }
    }
}
A123
B3 2 1
C1 2 3
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the loop

    The loop runs from 1 to 3, printing each number on its own line.
  2. Step 2: Confirm output format

    Each print outputs the current number followed by a newline.
  3. Final Answer:

    1 2 3 -> Option C
  4. Quick Check:

    For loop prints 1 to 3 sequentially [OK]
Quick Trick: For loops print each iteration on new line [OK]
Common Mistakes:
  • Assuming reverse order output
  • Expecting numbers concatenated without newlines
  • Thinking no output without explicit call

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes