Correct option is A
The variable i starts with the value 1. The loop runs while i < n, meaning it stops when i becomes equal to n. Therefore, the values printed will be:
i=1,2,3,……,(n-1)
Since the condition i < n fails at i = n, n is not printed.
Hence, the program prints all integers from 1 to (n – 1).
Important Key Points:
- In while loops, the condition is checked before execution, so the final value that violates the condition is not included.
- When a counter starts from 1 and runs while i < n, the total printed numbers are (n – 1).
- To include n, the condition must be written as i ≤ n instead of i < n.
Knowledge Booster:
- Counting up to i: Incorrect — i changes in each iteration; the final value is not constant.
- Counting up to (n + 1): Incorrect — loop never runs for i = n or beyond.
- Counting up to n: Incorrect — since i = n is not printed due to the < n condition.