Search code examples
loopsfor-loopif-statementpascal

How to fix an error in a for loop. Pascal


I wrote a programm, but there is an error that i can't understand.

Error: main.pas(23,11) Fatal: Syntax error, ")" expected but "ordinal const" found

program Hello; <-- 10 line
var 

x : integer;
y : integer;


begin


for x := 0 to 120 do

    begin
                                <-- error line
        if ( x % 5 = 0 ) then
            writeln (x);
    
    end;

  
end. <-- 30 line

Solution

  • x % 5 = 0 is the error.

    You probably want to use the modulo operator.

    % is the modulo operator in c and other languages. In pascal the modulo operator is mod.

    The correct statement would then be:

    if (x mod 5 = 0) then WriteLn(x);