Write Statement

Outputs the value of Expr1 with field width Expr2 and precision Expr3 to the WRT file of the user executing the write statement. You can write expressions of type string, char, float or number. Specification of the field width and the precision is optional. The precession argument (Expr3) is only valid for floating-point values; it is a non-negative integer that specifies the number of decimal places to be printed. If the number of characters in the output value is greater than the width specification, output values of type string are truncated. Output values of type string and char are printed left-justified. Output values of type number and float are printed right-justified.

The writeln statement advances to a new line in the output file.

Syntax

Stat = "write" "(" Expr1 [ "," Expr2 [ ","Expr3 ] ] ")" 
| "writeln" [ "(" Expr1 [ "," Expr2 [ ","Expr3 ] ] ")" ].

Example

dcltrans
  transaction TMain
  var
    I : number;
    a : array [10] of float;
  begin
    for I := 1 to 10 do
      a[i] := float(I)+0.5;

      if I mod 5 = 1 then
        writeln;
        write("Array a["); write(I, 2); write(" to ");
        write(I+4, 2); write("]: ");
      end;

      write(a[i], 6, 1);
    end;
  end TMain;

Output

Array a[ 1 to 5]: 1.5 2.5 3.5 4.5 5.5
Array a[ 6 to 10]: 6.5 7.5 8.5 9.5 10.5