Node: if, Next: Im, Previous: High, Up: Reference

### 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 known 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

Keywords, if Statement, else, then