What is the output of the following code? [code]i=0;for j=0:2 j=j-1 end[/code]

Tâm Tây

New member
What is the output of the following code?
Code:
i=0;for j=0:2  
j=j-1
end
A. Infinite loop
B. -1
C. Output is suppressed
D. +1
 
Answer: b
Explanation: The output is suppressed since there is a semi-colon after the decrement of j. The counter variable is really treated as a different variable hence the value of j at the end of the loop is not 2.
 

Tìm kiếm

Back
Top