functionpascal

Set function Succ(Pascal)


How could I set in Pascal function Succ? I mean when I put Succ in code it moves the ordinal number of character on next position. But only once. Is there way, that it could moves three times not just once?

I have found on the internet this code:

    function Succ (X: ordninal_type): ordninal_type;
    begin
      Ord (Succ (X)) = Ord (X) + 1;
    end;

My idea was to replace + 1 to + 3, but it puts me errors like:

program.lpr(6,36) Error: Identifier not found "ordninal_type"
program.lpr(19,23) Error: Incompatible type for arg no. 1: Got "Char", expected "<erroneous type>"

So how should I set the function, so I would set it in code, like -> CHARACTER:=Succ(CHARACTER);?


Solution

  • 'Succ' returns the successor (next value) after the current one. It can't increment more than one, because there is only one "next value".

    Use Inc instead:

    Inc(YourVariable, 3);
    

    Or you can directly increment in code:

    YourVariable := YourVariable + 3;
    

    If you're dealing with a character value (data type Char), you can use Inc as well:

    Ch := 'A';
    Inc(Ch, 3);  // Ch is now 'D'