Flowgorithm While Loop [ 2024 ]
Flowgorithm While Loop
In this tutorial, we will learn about the Flowgorithm While Loop Statement. The Flowgorithm tool offers three loop structures for repetitive statements in the flowcharts. The Looping structures are:
- While Loop
- For Loop
- Do While Loop
Flowgorithm While Loop
The While loop statement is a repetition structure and an indefinite loop. It is used when we don’t know how many iterations we need, when we want to loop until some condition is met, etc.
A loop construct is a condition-controlled loop and a pre-test loop structure. The loop condition is checked before the loop statements are executed.
To add a While loop construct, right-click the mouse on the control line and choose the While symbol/shape.
Double-click the While symbol to provide the Boolean expression in the While properties window. For each iteration, the Boolean expression is evaluated. If its expression evaluates to True, the loop statements are executed. This repetition continues until the Boolean expression is evaluated as false.
Example
Assume a flowchart to print users’ friends’ names. The flowchart will prompt the user to enter a friend’s name one at a time. We will display the friend’s name on the console window. The flowchart will exit when the user enters “QUIT” as a friend’s name.
Steps:
Declare a variable to hold the user input.
Assign an initial value to an empty string.
Add a while loop to the flow chart. We use while because we don’t know how many names the user will enter during the flowchart runtime.
Add loop statements.
Sample Output
Execute the flowchart.
Indefinite Loop
Loops are indefinite loops that can run forever based on conditions. Some applications are designed to run forever until they are interrupted by external signals. A real-world example of this is an application/web server that runs forever to service client requests. Let’s simulate a loop that runs forever until it’s stopped.
The while loop runs until the condition becomes false. The loop runs forever if we provide a condition that never evaluates to false.
Examples, conditions like:
while(1 = = 1)
while( True)
will always evaluate to True, and the loops will run forever.
Sample run output
This flowchart will run forever until it is stopped by an external signal, such as a user stopping the flowchart or encountering a runtime error.
Note that if the flowchart design doesn’t need an indefinite loop, this could be a defect or error.
—