To use the variables in a flowchart we need to create them. Variables are named memory locations to hold or store data in the program. The flowchart identifies each variable with a name called as Identifier or Variable name. Creating variables in a Flowgorithm flowchart is a two-step process.
- Declare the variable
- Assign a value to the variable.
We use the Declare shape to declare a variable. Give a name for the variable and specify the data type. To add the declare shape to the flowchart, click or left click on the arrow line between the Main and End symbols. Click on the Declare shape to add it.
Double click on the Declare shape to open the Declare properties Window. We can give the variable name and set the data type from the Type drop-down. Please note that Identifiers must start with a letter and avoid naming variables with reserved words.
To assign a value to a variable, double-click on the line and choose the Assign shape. Double click on the Assign shape to bring up the Assignment Properties window. Enter the variable name and the appropriate value and click on the OK button.
Sample Declare and Assign shapes in a flowchart. A foo variable is declared as an Integer data type. The foo variable is assigned 25 as value.
When we assign value to the variable for the first time its called initialization. We have initialized variable foo to 25.
Constant vs Variable
In the above example, the foo variable can be re-assigned to another variable in the program flow. A variable can change its value during the flowchart or program run. On the other hand, Constant doesn’t change its value during the program run. The value of the constant will be the same throughout the flowchart/program.
pi = 3.1415 (approx)
pi value is a constant in the program. The value of pi is predefined by the Flowgorithm. We can use constants in the flowchart. Once assigned the value of constant would not change during the program run. It’s a good programming practice to denote user-defined constants in the flowcharts in the uppercase.
Flowgorithm Tutorials Link: