Populate String Array with User Input
Populate String Array
In the earlier flowchart example, we hardcoded the array elements. In this tutorial, we will learn how to populate a string array with user input. Using this approach, the array’s contents would be dynamic.
Flowgorithm Flowchart
The ‘fruits’ variable is an array variable. The array holds fruit names, which are a String data type. It has a size of 5.
The ‘index’ is the Array index variable. The legal values of the array index variable in this example are from 0 to 4.
Loops
The flowchart uses two ‘for loops’. The first loop is to populate the array contents from the user and the second loop to output the contents of the array to the console window. A for loop is used because we know the array size beforehand and how many times to iterate the loop.
For loop
Flowgorithm For Loop Statement
Sample Output
Execute the flowchart. Click on the Green run command to execute the flowchart.
The flowchart prompts the user to enter 5 fruit names. The names are stored in the fruits array.
Bad Subscript Error
The below sample error is when we attempt to store or access an array element that is not within the valid range:
—
Flowgorithm Tutorials
https://www.testingdocs.com/flowgorithm-flowchart-tutorial/