What is the output of the following code? [code]for j= 4:2 j=j+1 end[/code]

Minh Tung

New member
What is the output of the following code?
Code:
for j= 4:2   
j=j+1 
end
A. an empty vector, j
B. 3
C. 2
D. error
 
Answer: a
Explanation: The loop never runs since if we want to decrease the counter value, we will have to introduce the decrement value. The default form, used here, is for increment operation. Hence, the output is an empty vector, j.
 

Tìm kiếm

Back
Top