1.5. Variable declaration

Felix also support mutable variables, which are declared with the 'var' keyword.
Start C++ section to tut/examples/tut105.flx[1 /1 ]
     1: include "std";
     2: var i = 1;
     3: var j : int;
     4: while {i < 10}
     5: {
     6:   j = i + i;
     7:   print j; print "\n";
     8:   ++i;
     9: };
End C++ section to tut/examples/tut105.flx[1]
Like value declarations, the type of a variable does not need to be declared if it is initialised. However, as you can see uninitialised variables are also permitted, and in this case the type must be given.

You will notice the assignment in the line:

  j = i + i;
Naturally, variables must be initialised or assigned to before they are used, as in C.

You will also have noticed the 'while' loop, one of the control structures Felix provides: it appears to work the same way as a 'while' loop in C, except that a trailing ; is strangely required, and the condition is given in curly brackets. We'll find out exactly why later, but here is a hint: there is no while statement in Felix!