Illegal use of reserved keyword "while"

1 view (last 30 days)
Hello,
please. This code working for me, but if my friend copy-paste this code he everytime get error: "Illegal use of reserved keyword "while".
You don't know where can be problem?
Code:
while 1
y = fix(input('Zadajte stlpce'));
if(y>=3 & y<=7)
break;
end
end
% Príkazom input načítam hodnoty a fix oddelí čísla za čiarkou.
while 1
x = fix(input('Zadajte riadky'));
if(x>=3 & x<=7)
break;
end
end
while 1
krok = fix(input('Krok'));
if(krok>=3 & krok<=7)
break;
end
end
V = zeros(x,y);
V(:) = 1;
% Vytvorila sa matica s nulami a V(:) ju vyplní jednotkami.
val = 1;
for Riadok = 1:y
for Stlpec = 1:x
if(val == krok)
V(Stlpec,Riadok) = Riadok+Stlpec;
V(1,1) = V(1,1) * V(Stlpec,Riadok);
val = 1;
else
val = val + 1;
end
end
end
% Val pomáha počítať k-tú hodnotu. Ak sa val==krok tak sa zapíše spočítaný
% riadok + stlpec a zapíše sa na dané súradnice. Potom sa urobí súčin
% daného čísla na prvý prvok.
V
% Vypíše sa matica.
  2 Comments
Walter Roberson
Walter Roberson on 3 Dec 2020
The code looks okay. The error is with something that the other person already has in the file before that point, or if they are already inside a statement at the command line. If they are at the command line, they should press control-C to end whatever they are already doing.
Image Analyst
Image Analyst on 3 Dec 2020
Have them type control-a (to select everything) then control-i (to properly indent). Does the indentation look OK after that, or are there statements that are misaligned, like maybe you're missing an "end" statement or something.

Sign in to comment.

Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!