More about Loops

MATLAB

This set of MATLAB Multiple Choice Questions & Answers (MCQs) focuses on “More about Loops – 1”.

1. What is the output of the following code?

i=0;for i=0:2  
i=1; end

a) Output is suppressed
b) Output shows 1 3 times
c) Output shows 1 2 times
d) Error

2. What is the output of the following code?

i=0;for j=0:2  
j=j-1
end

a) Infinite loop
b) -1
c) Output is suppressed
d) +1

3. What is the output of the following code?

a=0;for j=0:2  
j=j+1 end

a) Syntactical Error
b) 3
c) 2
d) Keyword Error

4. What is the final value of j from the following code?

for j=(0:3)  
j=j+1;
end

a) Syntactical error
b) Declaration error
c) 3
d) 4

5. What is the output of the following code?

for j= 4:2   
j=j+1 
end

a) an empty vector, j
b) 3
c) 2
d) error

6. What is the output of the following code?

for i!=1:10 
p=p+1;

a) Syntactical Error
b) Inf
c) NaN
d) Logical Error

7. In nested loops, the break statement exits the ____ loop.
a) external
b) last started ongoing
c) not available in MATLAB
d) for

8. In nested loops, the continue statement exits the ____
a) current iteration
b) loop
c) inner
d) outer

9. In nested loops, the break statement, if present within a nested if the structure, will exit the _______
a) Ongoing if structure
b) Entire loop
c) Ongoing loop
d) Entire if structure

10. In nested loops, the continue statement, if present within an if structure, will exit the ____________
a) If structure
b) current iteration
c) entire loop
d) Error

11. In nested loops, the continue statement, if present within a nested if structure, will exit the ____________
a) If structure
b) nested if structure
c) entire loop
d) present iteration

12. What is the output of the following code?

for j= 4:2:2   
j=j+4 
end

a) Error
b) j=6
c) Error an empty vector, j
d) Syntactical error

13. While running a loop in MATLAB, it does not require indentation.
a) True
b) False

14. The effective working of the continue keyword in the final iteration is same as the effective working of the break keyword.
a) True
b) False

15. The number of iterations run for any loop by MATLAB is always _____________
a) a positive integer
b) a negative integer
c) a number
d) a decimal number

16. The for loop performs at least ___ iteration/s.
a) 1
b) not necessarily an iteration
c) 2
d) Error

17. Multiple graphs can be plotted, in the same window, if we use the ___ command in a loop.
a) hold on
b) held on
c) hold off
d) not possible

18. The number of iterations in the following loop is

p=3;for i=(3:4)
p=p+2;
end

a) 0
b) 1
c) 3
d) 4

19. What is the output of the following code?

q=0;for i=(1:1)
q=q+5;
end

a) Output is suppressed
b) Syntactical error
c) q=5
d) Declaration error

20. What is the output of the following code?

a=0;for i=[1:1]
q=a-55;
end

a) Syntactical Error
b) Declaration error
c) Output is suppressed
d) q=-55

21. What is the nature of the error in the following statement?

for i=1:

a) Incomplete
b) Unexpected operator
c) Invalid keyword
d) No error

22. What is the nature of the error in the following statement?

for i=:1

a) Incomplete syntax
b) Unexpected MATLAB operator
c) No such keyword
d) No error

23. What is the output of the following code?

i=0; while[i<5] 
i=i+1;
end

a) Syntactical Error
b) Declaration Error
c) Output is suppressed
d) i=5

24. The condition of a while loop cannot be given in ________
a) ()
b) []
c) {}
d) <>

25. What is the output of the following code?

while{i<5}
i=i+1234;
end

a) i=1234
b) Output is suppressed
c) Error in converting the cell to logical form
d) Error in i

26. What is the output of the following code?

i=0;while(i<5)
i=i-1;
end

a) Error
b) i=-Inf
c) i=NaN
d) Infinite loop

Leave a Reply

Your email address will not be published. Required fields are marked *