Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Turbo Pascal - <b> succ return the successor of number pp 141</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 SUCC                   Return the Successor of Number                pp 141

 Syntax:  Succ (Scalar) ;

 Type:    Data type                   

 Form:    Function, procedure, declaration

 Purpose: Returns the preceeding value of an ordinal type.

 Notes:   Succ of the first value of an ordinal type is undefined.
          {$R-} strict range checking is off (default) then Succ will
          wrap around to zero minus one.  Type Byte wraps to 255 and type
          Integer wraps to -1 ($FFFE).


 ----------------------------------------------------------------------------



 Usage:
       TYPE
          Rainbo = (Red,Orange,Yellow,Green,Blue,Indigo,Violet) ;

       CONST
          Index  : Byte = 4 ;
          Colors : Array [0..6] of String [3] =
                   ('Red','Org','Yel','Grn','Blu','Ind','Vio');

       VAR
          Bands  : Rainbo                 ;  { Bands is type Rainbo        }
          ChrVar : Char                   ;  { Character variable          }
          BytVar : Byte                   ;  { Byte variable               }
          IntVar : Integer                ;  { Integer variable            }
          StrVar : String [3]             ;  { String variable             }


       BEGIN
          BytVar := Succ (255)            ;  { BytVar = 0                  }
          IntVar := Succ (0)              ;  { IntVar = 1                  }
          ChrVar := Succ ('X')            ;  { ChrVar = Y                  }
          Index  := Succ (Ord(Orange))    ;  { Set index to 2              }
          Bands  := Succ (Orange)         ;  { Bands = Yellow              }
          {$R+}                           ;  { Strict range checking on    }
          Bands  := Succ (Violet)         ;  { Undefined, gives R/T Err 91 }
          StrVar := Colors [Succ (Index)] ;      { Grn                     }
       END.

See Also: Ord Pred

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson