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

What is the output of the following code?
Code:
a=0;for j=0:2  
j=j+1 end
A. Syntactical Error
B. 3
C. 2
D. Keyword Error
 
Answer: d
Explanation: The end is a reserved keyword and it cannot be used in the same line with j+1. Hence, the for-loop will end without even beginning. The output would’ve been 3 if the end was in the next line. There is no syntactical error.
 

Tìm kiếm

Back
Top