What is the output of the following code? [code]while{i<5} i=i+1234; end[/code]

Pham Quỳnh

New member
What is the output of the following code?
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
 
Answer: c
Explanation: MATLAB returns the first error it finds. Now, i is not defined before using it as a variable for a condition in the while loop. But the first error is the fact that the condition is given in {} so it is in a cell format and the conversion to logical form is not possible. Hence, MATLAB will return an error.
 

Tìm kiếm

Back
Top