'How to fixed it? Pascal main.pas(21,6) Fatal : syntax error, ";" expected but "ELSE" found

Help me please 😊

program number_three;

uses crt;

var
i, j : integer;

begin
  for i := 1  to 5 do
  begin
    if (i mod 2 = 0) then
      begin   
        for j := 1  to 5 do  
        begin  
          if (j mod 2 = 0) then    
            begin       
              write('x ');    
            end    
          else  
            begin    
              write('o ');
            end
        end;   
    else   
      begin    
        for j := 1  to 5 do    
          begin   
            if (j mod 2 = 0) then
              begin     
                write('o ');     
              end
            else
          begin
            write('x '); 
          end 
       end;
    writeln('');
  end;
end.

Final result must be :

X O X O X O

O X O X O X

X O X O X O

O X O X O X

X O X O X O

Help me please



Solution 1:[1]

The end before the else must not be followed by a semicolon ;. In Pascal the semicolon is a statement separator more or less.


for i := 1 to 5 do
begin
  for j := 1 to 5 do
    if (i + j) mod 2 = 0 then
      write('X ')
    else
      write('O ');
  writeln('');
end;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1