In the script below, where should I insert the break command so that the code produces the following output:
10
11 12 26
a = 10; for i=a:i+10 if( a<13 ) ...(1)... disp(a); a = a+1; ...(2)... else disp(a*2); ...(3)... end ...(4)... end
a.
(4)
b.
(1)
c.
(3)
d.
(2)
Answer:
c.
(3)
Explanation:
The given script is:
a = 10; for i=a:i+10 if( a<13 ) ...(1)... disp(a); a = a+1; ...(2)... else disp(a*2); ...(3)... end ...(4)... end
For the first three passes of the for loop, the first if block will be executed and 10 11 12 will be printed. For the fourh pass the program will go inside the else statement where the value of a is 13 currently and 13*2 i.e. 26 will be printed. After that we should give the "break" keyword in order to stop execution at that time according to the given problem.
Get Answers For Free
Most questions answered within 1 hours.