Loop Statements
Loops allow the repetition of statements in the flowchart. Consider the simple example of printing a hundred numbers. We must add a hundred output statements to the flowchart to print the numbers without loops. This will make the flowchart too big and look cumbersome.
Loop structures allow the repetition of statements. So, with a loop, we can add a single Output statement and iterate the loop a hundred times.
The Flowgorithm supports three loop statements.
- While Loop
- For Loop
- Do Loop
For Loop: The For loop executes a code block a specific number of times. It typically has an initialization, condition, and update expression. This loop is known as the definite loop.
While Loop: The While Loop executes a code block repeatedly until the loop condition is true. This loop is called an indefinite loop.
Do Loop: This is similar to the While loop, but the condition is evaluated after executing the code block, so it always executes at least once.