Create Variables
The Declare statement creates variables in the flowchart. This symbol can also be used to create multiple variables. Creating variables in the flowchart is a two-step process.
- Declare the Variable
- Store/Assign a value to the Variable.
Examples
Let’s create a single variable called ‘age’ of the datatype Integer. The steps are outlined below:
Launch Flowgorithm software.
Right-click on the flow control line. Choose the Declare symbol under the Variables section.Â
Â
In the Variables Names: box, specify the variable name as age. Choose the Type: as Integer.Â
Click on the OK button to create the variable.Â
Store a value
When we create a variable with the Declare symbol, its initial value is undefined or uninitialized. We can use the Assign symbol to store a value in the variable.Â
Â
Points to remember
A variable must be declared before it can be used in the flowchart. The interpreter will throw an error if it encounters a variable that is not declared.Â
For example, the error screen shows that the sum variable is used without declaration.
Â
A variable can change its value during the program’s lifetime. Let’s understand this concept with an example.Â
Create a variable called x. Let’s assign multiple values to the variable x and check its output.Â
Notice that variable x holds different values we assigned during the flowchart run. Initially, x holds a value of 56, but with the second assignment statement, we changed the x value to 79.