V
V
Viktor Pomokaev2020-09-17 20:15:05
Pascal
Viktor Pomokaev, 2020-09-17 20:15:05

Why does it give the error "Met 'else' but expected ';'"?

program BegemotKashelot;
var x, y: integer;
begin
writeln('Введите x =');
read(x);
if x < -1 then
begin
y:= 2-sqr(x);
writeln('y=',y)
end
else
begin
if (x>=-1) and (x<=2) then
y:= 2*x;
writeln('y=',y);
end
else
if x>2 then
begin
y:= 2-x;
writeln('y=',y);
end

end.

Program1.pas(17) : Встречено 'else', а ожидалось ';'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
HemulGM, 2020-09-17
@HemulGM

Because you can't write

if

else

else

Only one else can be used.
What does "If 1 then ..., otherwise ..., otherwise ..." mean? In what other case?
if ...
begin

end
else
  if ...
  begin
  
  end
  else
    if ...
    begin
    
    end;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question