Variables Basics

Quick Recap

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:

Without type declaration

x : 20;

In which the compiler will figure out the type for you or

With type declaration

int x : 20;

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.

Last updated