Sign in Join
Wiki copytemporary

Revision 1 of 2, by Kai Burghardt on 1-26-2021. The page as it is now.

Slash

<div style="float:right; margin: 0 25px 20px 0; padding:50px; font-size:500%; font-family: Georgia; background-color: #f9f9f9; border: 2px solid #777777;">

/

</div>

A single slash, surrounded by non-slash characters is regarded as the division operator. Two consecutive slashes are regarded as comment introducers.

division

The ASCII slash / is used in a Pascal program to perform division (∕ U+2215 “division slash”). The results are always real values. If you want to perform integer division the div operator has to be used.

pascal
A := 3 / 4;

After this operation the variable A holds the value 0.75 (assuming A is declared as a real value type, otherwise the compiler generates an incompatible type error).

related exceptions

The value on the right side of the slash must not be zero, or a division by zero error occurs. In modes where exceptions are available (e.g. ObjFPC and Delphi mode) this condition can be caught by using a try … except frame. Otherwise a run-time error occurs (RTE 200).

pascal
program divZeroDemo(input, output, stderr);

// ObjFPC mode for exceptions
{$mode objfpc}

uses
    // make exception EDivByZero known
    sysutils;

const
    dividend = 1.1;

resourcestring
    enterDivisorPrompt = 'Enter divisor:';
    divisionOperationExceptionless = 'Division did not cause an exception.';
    zeroDivisionFailure = 'Error: Attempted to divide by zero.';

var
    divisor, quotient: single;

begin
    writeLn(enterDivisorPrompt);
    readLn(divisor);
    
    try
        quotient := dividend / divisor;
        writeLn(divisionOperationExceptionless);
    except on EDivByZero do
        writeLn(zeroDivisionFailure);
    end;
end.

Note: Exception handling is expensive. A plain test whether the user input is non-zero would have been in the above example more sophisticated.

comment

Two slashes back to back introduce comments till the end of line. This is also known as “Delphi-style comment”.

delphi
while (buf^ in [' ', #9, #10]) do // kill separators

<small>example source</small>

see also


From the Free Pascal wiki, page "Slash", as it stood on 2021-01-26 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.