What will the following code do? [code]j=0;i=5; while(j<0) j=j-1; i=i+5;j=i; end[/code]

What will the following code do?
Code:
j=0;i=5;
while(j<0)
j=j-1; i=i+5;j=i;
end
A. Nothing
B. j=0 & i=5
C. Error
D. Cannot be determined
 
Answer: b
Explanation: We observe that the while loop will enter into an infinite loop. Hence the final value of i and j won’t be determined by MATLAB. MATLAB will retain the values for i and j as they were initialized. Hence j will remain 0 and i will remain 5. There is no error in the code.
 

Tìm kiếm

Back
Top