Flowgorithm Nested For Loops
In this tutorial, we will learn about Nested for loops in Flowgorithm flowcharts. A for loop placed inside another for loop is called a nested for loop. In general, the outside loop is called the outer for loop. The loop placed inside is called the inner for loop.
Number of Iterations
If the outer loop iterates for M iterations and the inner loop iterates for N iterations, the total number of iterations the whole nested for loop construct iterates is
Total = M * N iterations.
In this example, we will draw a square pattern with the asterisk(*) character using nested for loops in the flowchart.
The general steps to design the flowchart are as follows:
Launch Flowgorithm flowchart tool.
Declare variables N, and loop counter variables like i and j. The i variable is to control the outer for loop. The j variable is to control the inner for loop.
Prompt user to enter the variable N. The number of rows in the pattern.
Add two for loop statements
The outer loop runs N times to print N rows. The Inner for loop run to print N asterisk characters.
In the inner for loop print the asterisk character to the console and remove the New line option.
In the outer for loop add a blank Output symbol and check the New Line check box. This will carriage return and go to the next line for the next for loop iteration.
That’s it. We have successfully designed a flowchart to print the square pattern with * character.
Now that you have learned to print the square pattern. Modify or create a new flowchart to print a triangle pattern.
The Nth row of the pattern should print N * characters.
Print Triangle Pattern to a File
Flowgorithm 3.0 version supports File I/O symbols. Print the triangle pattern with * character to an output file, for example to an output.txt text file.
Flowgorithm flowchart tutorials on this website:
For more information on the Flowgorithm tool, please visit the official website at: http://flowgorithm.org/