Variables Basics
Last updated
Last updated
In the Basics section, we successfully executed our first Cylvre program, found out that all executable code goes in the main() function and learnt the most basic statement in any language : the print statement.
Now we will move on to the next topic, Variables!
Variables are essentially little storehouses of information. It can be the output of a function or statement, or be reassigned multiple values based on the outcome of the program.
Now, variable declaration in Cylvre is easy, and you can do it two ways:
In which the compiler will figure out the type for you or
Currently, the compiler only supports variable declaration with value.
Something that may stand out to you is the use of :
instead of =
for assignment. This was done to free up the '=' for conditional equality instead, which makes the if statement of Cylvre very easy to read and write, but we'll get to that in a bit.
You don’t necessarily have to declare the type explicitly, the compiler can infer the type of the variable.
Type Keyword
Type
Example
char
Character
c, x, A
int
Integer
12, -37
str
String
learn, Cylvre
float
Decimal
12.37
double
Decimal (higher precision)
3.14159265...
bool
Boolean
true, false
byte
Integer (stores value of up to 1 byte)
10, 25
long
Integer (stores numbers of high value)
31415936
short
Integer (opposite of long)
75, 50, 12