Assignment Statement
An assignment statement is used to assign a value to a variable. In Lipi, you can assign a value to an existing variable, but you cannot assign a value at the time of declaration.
Syntax
variable_name = expression;Basic Assignment
You can assign a literal value to a variable:
purna age;
age = 25; :) Assigns the value 25 to the variable age
dasa pi;
pi = 3.14159; :) Assigns the value 3.14159 to the variable pi
akshar grade;
grade = 'A'; :) Assigns the character 'A' to the variable grade
paath name;
name = "John"; :) Assigns the string "John" to the variable nameAssignment with Expressions
You can also assign the result of an expression to a variable:
purna a;
purna b;
purna sum;
a = 5;
b = 10;
sum = a + b; :) Assigns the result of a + b (15) to the variable sum
purna x;
x = sum * 2; :) Assigns the result of sum * 2 (30) to the variable xImportant Notes
- The variable must be declared before it can be assigned a value.
- The type of the value being assigned must match the type of the variable.
- You cannot assign a value at the time of declaration.
Next Steps
Now that you understand assignment statements in Lipi, you can learn more about: