Questions: The program should output even values between -10 and 10 (inclusive),
-10 -8 ... 810
What should XXX be?
i=-10 ;(i * 2)<=10,++i
i=-10 ;(i * 2)<10 ;++i
i=-10 ; i<10 ; i=i+2
i=-10 ; i<=10 ; i=i+2
Transcript text: The program should output even values between -10 and 10 (inclusive),
-10 -8 ... 810
What should XXX be?
$i=-10 ;(i * 2)<=10,++i$
$i=-10 ;(i * 2)<10 ;++i$
$i=-10 ; i<10 ; i=i+2$
$i=-10 ; i<=10 ; i=i+2$
Solution
The answer is the fourth one: i=-10 ; i<=10 ; i=i+2
Explanation for each option:
i=-10 ;(i * 2)<=10,++i: This option is incorrect because the condition (i * 2)<=10 is not appropriate for generating even numbers between -10 and 10. Additionally, the syntax is incorrect due to the use of a comma instead of a semicolon.
i=-10 ;(i * 2)<10 ;++i: This option is incorrect for similar reasons as the first one. The condition (i * 2)<10 does not correctly iterate over the even numbers between -10 and 10. The loop will not include 10, which is part of the required output.
i=-10 ; i<10 ; i=i+2: This option is incorrect because the condition i<10 will stop the loop before reaching 10. Therefore, it will not include 10 in the output, which is required.
i=-10 ; i<=10 ; i=i+2: This option is correct. The loop starts at -10 and increments by 2 each time, which ensures that only even numbers are considered. The condition i<=10 ensures that the loop includes 10 in the output, which matches the requirement of the problem.
In summary, the correct loop to output even values between -10 and 10 (inclusive) is i=-10 ; i<=10 ; i=i+2.