Difficulty: Easy
Correct Answer: int i; for (i = 0; i <= 10; i++) Console.WriteLine(i);
Explanation:
Introduction / Context:The task is to find an equivalent loop to print integers from 0 through 10 inclusive. We compare do-while, for, and while variants and check boundaries and syntax validity.
Given Data / Assumptions:
Concept / Approach:Translate loop semantics: initialization, condition, increment, and body must match. A for loop with i = 0; i <= 10; i++ matches perfectly.
Step-by-Step Solution:
Initialize i to 0. Ensure termination check i <= 10. Increment i by 1 after each iteration. for (i = 0; i <= 10; i++) Console.WriteLine(i); prints exactly the same sequence.Verification / Alternative check:Count outputs: 11 lines, from 0 to 10 inclusive. The for loop yields identical count and values.
Why Other Options Are Wrong:
Common Pitfalls:Off-by-one errors when translating conditions or using the non-existent until syntax in C#.
Final Answer:for (i = 0; i <= 10; i++) Console.WriteLine(i);
Discussion & Comments