Lipi

Variables

You use variables as symbolic names for values in your application. The names of variables, called identifiers, must conform to the rules of identifiers.

Variable Declaration

A variable can be declared in Lipi using the following syntax:

type identifier;

Only one variable can be declared at a time, and each variable must have a unique identifier. Also, values cannot be assigned to variables at the time of declaration.

purna x;       :) Valid
purna x, y, z;  :) Invalid
purna x = 5;    :) Invalid

Variable Assignment

After declaring a variable, you can assign a value to it using the assignment operator =.

purna age;     :) Declare an integer variable
age = 25;     :) Assign a value to the variable

dasa pi;      :) Declare a decimal variable
pi = 3.14159; :) Assign a value to the variable

Variable Usage

Once a variable is declared and assigned a value, you can use it in expressions, pass it to functions, or print its value.

purna a;
purna b;
purna sum;

a = 5;
b = 10;
sum = a + b;  :) sum will be 15

bhana(sum);   :) Print the value of sum

Variable Scope

Variables in Lipi have block scope, which means they are only accessible within the block they are declared in. A block is a section of code enclosed in curly braces .

Next Steps

Now that you understand variables in Lipi, you can learn more about: