- A 1, 3, 5, 7, 9
- B 1, 4, 7, 10
- C 0, 3, 6, 9
- D 0, 1, 3, 6, 9
- Share this MCQ
Answer:
A
Share this MCQ
Justification:
- 1, 3, 5, 7, 9 is the correct output. We declare the counter variable of type int inside the For loop and initialize it’s value to 1. The second clause of the For loop tells it to continue looping as long as the condition is met that the counter variable is less than 10. The third clause specifies how the counter will increment or change each time the loop executes. In the block of code, we also decrement the counter by 1 using the syntax “counter- -“. Therefore, we observe the output, which prints at 1 and increases by 2 each time.
- The output will not increase by 3 each time due to the counter variable being decremented by one inside the block of code, after it prints. The upper limit for the For loop is “9” since the condition is “<10”; therefore, the value of 10 would not print.
- The first value must be 1, since that is what the counter is initialized to, and enters the loop with that value. We would not observe a value of 0 with this code.
- The first value must be 1, since that is what the counter is initialized to, and enters the loop with that value. We would not observe a value of 0 with this code.
Related Lesson: Basic Syntax
Click me to Read more Question & Answer of Module 12: X++ OverviewShare this MCQ