What is the output of the following code? [code]for i!=1:10 p=p+1;[/code]

Ngoc Hue

New member
What is the output of the following code?
Code:
for i!=1:10 
p=p+1;
A. Syntactical Error
B. Inf
C. NaN
D. Logical Error
 
Answer: d
Explanation: While mentioning the number of times a loop would run, we have made an error in defining the range. The above statement, really, signifies that the loop won’t run for i= [1,10]. So we did not mention, when the loop will actually run. This results in the error.
 

Tìm kiếm

Back
Top