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

## 9.110 if

### Synopsis

    if Boolean expression then
      statement

or with an alternative statement:

    if Boolean expression then
      statement1
    else
      statement2

### Description

The ``if ... then'` statement executes statement1 depending on ``Boolean expression'` being true. If ``else'` is specified, it continues executing statement2 instead.

### Conforming to

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

### Example

    program IfDemo;
    var
      Foo, Bar: Boolean;
    begin
      Foo := True;
      Bar := False;
      if ((1 = 1) or (2 = 3)) and (Foo = not Bar) then
        begin
          { This is executed if either Foo is true but not Bar or vice versa }
          WriteLn ('Either Foo or Bar is true.');
          if Bar then
            WriteLn ('You will see this text if Bar is true.')
        end
      else { This whole `else' branch is not executed }
        if 1 = 1 then
          if True = False then
            WriteLn ('This text is never written on screen.')
          else  { Note: This ``else'' belongs to ``if True = False'' }
            WriteLn ('This text is never written on screen as well.')
        else  { Note: This ``else'' belongs to ``if 1 = 1'' }
          WriteLn ('Nor is this.')
    end.

### See also

section 8.1.7.3 if Statement, section 9.68 else, section 9.274 then

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