Flowgorithm

Flowgorithm Nested For Loops

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.

Example

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.

Nested For Loops Flowgorithm

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.

Sample Output

Nested Loop Flowchart Output Flowgorithm

That’s it. We have successfully designed a flowchart to print the square pattern with * character.

Exercises

#1

Triangle Pattern

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.

Exercise Nested For Loop Flowgorithm

#2

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 Tutorials

Flowgorithm flowchart tutorials on this website: