Single Choice
Easy
QYou have the following X++ statement:
For(int counter = 1; counter<10; counter+=3)
{
Info(strfmt(“%1”, counter));
Counter--;
}
You need to identify the output of the statement.
What should you identify?
ID: #9375
X++ Overview in D365 F&O
209 views
Question Info
#9375Q ID
EasyDifficulty
X++ Overview in D365 F&OTopic
Your Answer
Choose the Best Option
Click any option to instantly check if you're correct.
Correct Answer
Explanation
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
Continue Practice
Share
Share This Question
Challenge a friend or share with your study group.
More from This Topic