<< Home | About Forth | About TurboForth | Download | Language Reference | Resources | Tutorials | YouTube >>


7 Constants

Constants simply allow the Forth programmer to use a word to represent a number. Once declared, their value cannot be changed. There are three reasons for using Constants in Forth programs:

 

7.1 Declaring Constants with CONSTANT

Constants should be declared outside of a colon definition, like this:

    99 CONSTANT NinetyNine

As can be seen, CONSTANT requires a number on the stack, followed by the name of the constant to create.

 

7.2 Using Constants

Using constants in your code could not be simpler; simply name them. For example:

    99 CONSTANT NinetyNine
    : TEST NinetyNine 0 DO I . LOOP ;

<-- Back to Tutorials


<< Home | About Forth | About TurboForth | Download | Language Reference | Resources | Tutorials | YouTube >>