Constants
Constants in Crabby are immutable, meaning that once a constant is assigned a value, it cannot be changed. This is a fundamental aspect of the language that helps prevent accidental modification of data.
To declare a constant, you use the const keyword followed by the name of the constant and its value. For example:
const PI: Float = 3.14159
const MAX_USERS: Int = 100
In this example, we have declared two constants: PI and MAX_USERS. PI is assigned the value 3.14159, and MAX_USERS is assigned the value 100.
Constants can be used in expressions and calculations, just like variables. For example:
const radius: Float = 10
const area: Float = PI * radius * radius
In this example, we calculate the area of a circle with a given radius.