MATLAB: For loops and the if statement

forifMATLAB

This is a beginner question im sure i just dont understand why is it that i have to use 2 equal signs in the if statement?
for n=0:10;
fprintf('n=%d\n',n);
if n==0
i cannot use n=0 ??
thanks BN

Best Answer

n=0
Is an assignment; it assigns the value 0 to the variable n
n==0
is a logical test; it tests whether the variable n is equal to 0 and returns a boolean (true/false)