Site icon TestingDocs.com

Flowgorithm Do While Statement

Overview

In this tutorial, we will learn about the Flowgorithm Do While Loop Statement. In the Do While Loop structure, the loop statements are executed before the loop condition check. Like the While loop, the Do While loop is an indefinite loop. We can use this loop when we don’t know how many times the loop will run.

However, unlike the While statement, the Do While loop checks the condition after executing the loop statements. So the loop statements are executed at least once.

Do While Loop

To add the Do While loop to the flowchart, right-click on the control flow line and choose the Do loop statement.

 

 

Example

Let’s look into an example where the Do While loop is used. It’s a menu-based program to perform two actions based on the user input.

The Do While loop is natural for menu-based loops. The loop displays the menu statements and prompts the user to take different actions. Based on the user input the Do while loop executes the loop or terminates.

 

 

Pseudocode

Function Main
... Demo Flowchart for Do While Loop 
... - www.TestingDocs.com
Declare Integer userChoice

Loop
  Output "Program Menu:"
  Output "1. Task1"
  Output "2. Task 2"
  Output "3. Quit"
  Output "Please choose menu option:"
  Input userChoice
  If userChoice == 1
    Output "Performing Task 1 ..........."
  End
  If userChoice == 2
    Output "Performing Task 2 ..........."
  End
Do userChoice != 3
End

Sample Output

Run the flowchart to see how the loop runs and displays the menu for the user until the user chooses to quit.

Program Menu:
1. Task1
2. Task 2
3. Quit
Please choose menu option:
1
Performing Task 1 ...........
Program Menu:
1. Task1
2. Task 2
3. Quit
Please choose menu option:
2
Performing Task 2 ...........
Program Menu:
1. Task1
2. Task 2
3. Quit
Please choose menu option:
1
Performing Task 1 ...........
Program Menu:
1. Task1
2. Task 2
3. Quit
Please choose menu option:
3

Flowgorithm Tutorials

https://www.testingdocs.com/flowgorithm-flowchart-tutorial/

 

Exit mobile version