Using Constants

Constants are read-only named values. The following statement, for example, defines a constant named PSWD that’s equal to "sesame":

Const PSWD = "sesame"

Having coded this statement, you could use the name PSWD instead of the literal "sesame" in your code. This makes it easier to find and update the password when necessary. Constants are also a good solution when you use the same value several times in your code and it’s important that you code this value exactly the same way in each instance.

The rules for naming constants are the same as those for naming variables. However, it’s customary to name constants in all upper case. This distinguishes constants from variables when you use them in other parts of your code.

You can also use ...

Get Faster Smarter Beginning Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.