[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 9.172 nil

### Synopsis

``nil'` is a predefined constant

### Description

``nil'` is a predefined pointer constant that indicates an unassigned pointer. "nil" stands for "not in list". Every pointer type can be associated with this constant.

### Conforming to

``nil'` is defined in ISO-7185 Pascal and supported by all known Pascal variants.

### Example

    program NilDemo;
    const
      NodeNum = 10;
    type
      PNode = ^TNode;
      TNode = record
        Key: Integer;
        Next: PNode
      end;
    var
      Root, Node: PNode;
      Foo: Integer;
    begin
      New (Root);
      Root^.Key := 1;             { Set root key }
      Node := Root;
      for Foo := 2 to NodeNum do  { Create linked list with NODE_NUM nodes }
        begin
          New (Node^.Next);
          Node := Node^.Next;
          Node^.Key := Foo        { Set key }
        end;
      Node^.Next := nil;          { Mark end of linked list }
      { Shorten list by removing its first element until list is empty }
      while Root <> nil do
        begin
          Node := Root;
          WriteLn ('Current key:', Root^.Key);
          Root := Root^.Next;
          Dispose (Node);
          Node := nil             { Indicate old node is not assigned }
        end
    end.

### See also

section 9.19 Assigned, section 9.196 Pointer

This document was generated by Frank Heckenbach on May, 10 2002 using texi2html