George
George

Reputation: 87

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

Upvotes: 0

Views: 2053

Answers (1)

LU RD
LU RD

Reputation: 34899

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);

Upvotes: 1

Related Questions