why am I getting parse error as soon as I start loop ?

As soon as I type for, if etc. I get,
Parse error at <EOL>: usage might be invalid matlab syntax.
I get this error even if I do not write a single line of code.

3 Kommentare

"I get this error even if I do not write a single line of code."
Did you try to run a script or function file?
loops such as "for" of "if" statements should be ended with a keyword "end".
This is the code,
a = input('Enter first no: ');
b = ('Enter second no: ');
q=a/b;
if
b = 0;
fprintf('b cannot be zero');
else
fprintf('The quotient of given numbers is: %d\n', q);
end

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 12 Dez. 2022

1 Stimme

the expression for the condition of if or while must start on the same line, not the next line.
Comparisons are == not =

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

am 12 Dez. 2022

Kommentiert:

am 20 Dez. 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by